You are here

function easy_install_form_alter in Easy Install 8.7

Same name and namespace in other branches
  1. 8.9 easy_install.module \easy_install_form_alter()
  2. 8.10 easy_install.module \easy_install_form_alter()
  3. 8.2 easy_install.module \easy_install_form_alter()
  4. 8.3 easy_install.module \easy_install_form_alter()
  5. 8.4 easy_install.module \easy_install_form_alter()
  6. 8.5 easy_install.module \easy_install_form_alter()
  7. 8.6 easy_install.module \easy_install_form_alter()
  8. 8.8 easy_install.module \easy_install_form_alter()

Implements hook_form_alter().

File

./easy_install.module, line 15
Easy uninstall module file.

Code

function easy_install_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  $form_ids = [
    'system_modules_uninstall_confirm_form',
  ];
  if (in_array($form_id, $form_ids)) {
    $modules = \Drupal::service('keyvalue.expirable')
      ->get('modules_uninstall')
      ->get(\Drupal::currentUser()
      ->id());
    foreach ($modules as $module) {
      $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;
        }
        if (!empty($options)) {
          $form['modules_config'][$module]['configs'] = [
            '#type' => 'checkboxes',
            '#label' => $config_value->name,
            '#title' => t('Select the configurations to be deleted'),
            '#options' => $options,
            '#validated' => TRUE,
          ];
        }
      }
    }
    if (!empty($options)) {
      foreach (array_keys($form['actions']) as $action) {
        if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
          $form['actions'][$action]['#submit'][0] = 'easy_install_form_submit';
        }
      }
      $form['all_configs'] = [
        '#type' => 'checkbox',
        '#label' => t('Delete all the listed configurations'),
        '#title' => t('Delete all the listed configurations'),
        '#validated' => TRUE,
      ];
    }
  }
}