You are here

public function ModulesUninstallConfirmForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/src/Form/ModulesUninstallConfirmForm.php \Drupal\system\Form\ModulesUninstallConfirmForm::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 ConfirmFormBase::buildForm

File

core/modules/system/src/Form/ModulesUninstallConfirmForm.php, line 148

Class

ModulesUninstallConfirmForm
Builds a confirmation form to uninstall selected modules.

Namespace

Drupal\system\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Retrieve the list of modules from the key value store.
  $account = $this
    ->currentUser()
    ->id();
  $this->modules = $this->keyValueExpirable
    ->get($account);

  // Prevent this page from showing when the module list is empty.
  if (empty($this->modules)) {
    $this
      ->messenger()
      ->addError($this
      ->t('The selected modules could not be uninstalled, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'));
    return $this
      ->redirect('system.modules_uninstall');
  }
  $data = $this->moduleExtensionList
    ->getList();
  $form['text']['#markup'] = '<p>' . $this
    ->t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>';
  $form['modules'] = [
    '#theme' => 'item_list',
    '#items' => array_map(function ($module) use ($data) {
      return $data[$module]->info['name'];
    }, $this->modules),
  ];

  // List the dependent entities.
  $this
    ->addDependencyListsToForm($form, 'module', $this->modules, $this->configManager, $this->entityTypeManager);
  return parent::buildForm($form, $form_state);
}