You are here

public function PurgeConfigurationsForm::buildForm in Easy Install 8.9

Same name and namespace in other branches
  1. 8.10 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildForm()
  2. 8.5 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildForm()
  3. 8.6 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildForm()
  4. 8.7 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildForm()
  5. 8.8 src/Form/PurgeConfigurationsForm.php \Drupal\easy_install\Form\PurgeConfigurationsForm::buildForm()

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

src/Form/PurgeConfigurationsForm.php, line 113

Class

PurgeConfigurationsForm
Provides module installation interface.

Namespace

Drupal\easy_install\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'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'table-filter',
        'js-show',
      ],
    ],
  ];
  $form['filters']['text'] = [
    '#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 uninstalled module name
        or description to delete its garbage configuration'),
    '#attributes' => [
      'class' => [
        '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']) && !$module->status) {
      $package = $module->info['package'];
      $form['modules'][$package][$filename] = $this
        ->buildRow($modules, $module, $distribution);
      $form['modules'][$package][$filename]['#parents'] = [
        'modules',
        $filename,
      ];
    }
  }

  // Add a wrapper around every package.
  foreach (Element::children($form['modules']) as $package) {
    $form['modules'][$package] += [
      '#type' => 'details',
      '#title' => $this
        ->t('@package', [
        '@package' => $package,
      ]),
      '#open' => TRUE,
      '#theme' => 'system_modules_details',
      '#attributes' => [
        'class' => [
          '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'], [
    '\\Drupal\\Component\\Utility\\SortArray',
    'sortByTitleProperty',
  ]);
  $form['#attached']['library'][] = 'system/drupal.system.modules';
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Purge Configurations'),
    '#button_type' => 'primary',
  ];
  return $form;
}