ModulesListForm::buildForm

public ModulesListForm::buildForm(array $form, FormStateInterface $form_state)

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

core/modules/system/src/Form/ModulesListForm.php, line 115

Class

ModulesListForm
Provides module installation interface.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  require_once DRUPAL_ROOT . '/core/includes/install.inc';
  $distribution = drupal_install_profile_distribution_name();

  // Include system.admin.inc so we can use the sort callbacks.
  $this->moduleHandler->loadInclude('system', 'inc', 'system.admin');

  $form['filters'] = array(
    '#type' => 'container',
    '#attributes' => array(
      'class' => array('table-filter', 'js-show'),
    ),
  );

  $form['filters']['text'] = array(
    '#type' => 'search',
    '#title' => $this->t('Filter modules'),
    '#title_display' => 'invisible',
    '#size' => 30,
    '#placeholder' => $this->t('Filter by name or description'),
    '#description' => $this->t('Enter a part of the module name or description'),
    '#attributes' => array(
      'class' => array('table-filter-text'),
      'data-table' => '#system-modules',
      'autocomplete' => 'off',
    ),
  );

  // Sort all modules by their names.
  $modules = system_rebuild_module_data();
  uasort($modules, 'system_sort_modules_by_info_name');

  // Iterate over each of the modules.
  $form['modules']['#tree'] = TRUE;
  foreach ($modules as $filename => $module) {
    if (empty($module->info['hidden'])) {
      $package = $module->info['package'];
      $form['modules'][$package][$filename] = $this->buildRow($modules, $module, $distribution);
    }
  }

  // Add a wrapper around every package.
  foreach (Element::children($form['modules']) as $package) {
    $form['modules'][$package] += array(
      '#type' => 'details',
      '#title' => $this->t($package),
      '#open' => TRUE,
      '#theme' => 'system_modules_details',
      '#attributes' => array('class' => array('package-listing')),
      // Ensure that the "Core" package comes first.
      '#weight' => $package == 'Core' ? -10 : NULL,
    );
  }

  // If testing modules are shown, collapse the corresponding package by
  // default.
  if (isset($form['modules']['Testing'])) {
    $form['modules']['Testing']['#open'] = FALSE;
  }

  // Lastly, sort all packages by title.
  uasort($form['modules'], array('\Drupal\Component\Utility\SortArray', 'sortByTitleProperty'));

  $form['#attached']['library'][] = 'system/drupal.system.modules';
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Install'),
    '#button_type' => 'primary',
  );

  return $form;
}
doc_Drupal
2016-10-29 09:29:37
Comments
Leave a Comment

Please login to continue.