You are here

public function PurgeConfigurationsConfirmForm::buildForm in Easy Install 8.5

Same name and namespace in other branches
  1. 8.9 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm::buildForm()
  2. 8.10 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm::buildForm()
  3. 8.6 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm::buildForm()
  4. 8.7 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm::buildForm()
  5. 8.8 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm::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

src/Form/PurgeConfigurationsConfirmForm.php, line 125

Class

PurgeConfigurationsConfirmForm
Builds a confirmation form to uninstall selected modules.

Namespace

Drupal\easy_install\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['install'])) {
    drupal_set_message($this
      ->t('The selected modules could not be Purged, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error');
    return $this
      ->redirect('easy_install.purge_configurations');
  }
  $data = system_rebuild_module_data();
  $form['text']['#markup'] = '<p>' . $this
    ->t('Select the following configurations, selected configs will be completely deleted from your site!') . '</p>';
  $form['modules'] = [
    '#theme' => 'item_list',
    '#items' => $this->modules['install'],
  ];
  foreach ($this->modules['install'] as $module => $module_name) {
    $install_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
    $details = file_scan_directory($install_dir, "/\\.(yml)\$/");
    if (!empty($details)) {
      $form['modules_config'][$module] = [
        '#type' => 'details',
        '#title' => t('@name', [
          '@name' => $module,
        ]),
        '#description' => t('We found that @description module have configurations with it, if you like to delete it Please select the checkbox', [
          '@description' => $module,
        ]),
        '#weight' => 0,
        '#validated' => TRUE,
        '#open' => TRUE,
      ];
      $details = file_scan_directory($install_dir, "/\\.(yml)\$/");
      $options = [];
      foreach ($details as $config_value) {
        $options[$config_value->name] = $config_value->name;
      }
      $form['modules_config'][$module]['configs'] = [
        '#type' => 'checkboxes',
        '#label' => $config_value->name,
        '#title' => t('Select the configurations to be deleted'),
        '#options' => $options,
        '#validated' => TRUE,
      ];
    }
  }
  $form['all_configs'] = [
    '#type' => 'checkbox',
    '#label' => t('Delete all the listed configurations'),
    '#title' => t('Delete all the listed configurations'),
    '#validated' => TRUE,
  ];
  return parent::buildForm($form, $form_state);
}