You are here

function easy_install_form_submit in Easy Install 8.10

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

Implements custom submit().

Submit function to delete & unintall the selected configs & modules.

Parameters

array $form: The form array of uninstall confirm form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state value of uninstall confirm form.

1 string reference to 'easy_install_form_submit'
easy_install_form_alter in ./easy_install.module
Implements hook_form_alter().

File

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

Code

function easy_install_form_submit(array $form, FormStateInterface $form_state) {

  // Get the current user and to get the modules that are selected.
  $account = \Drupal::currentUser()
    ->id();
  $modules_list = \Drupal::service('keyvalue.expirable')
    ->get('modules_uninstall');
  $modules = $modules_list
    ->get($account);
  $module_handler = \Drupal::service('module_installer');

  // Uninstall the modules and delete the keyvalue.
  $module_handler
    ->uninstall($modules);
  $modules_list
    ->delete($account);

  // To message the users whether the selected configurations deleted or not.
  $config_deteted = FALSE;

  // Get the user selected configs in install folder and delete.
  $ins_configs = $form_state
    ->getValue('configs') ? $form_state
    ->getValue('configs') : [];
  if ($form_state
    ->getValue('ins_all_configs') != 0) {
    foreach ($ins_configs as $key => $value) {
      Drupal::configFactory()
        ->getEditable($key)
        ->delete();
    }
    $config_deteted = TRUE;
  }
  else {
    foreach ($ins_configs as $key => $values) {
      if ($values !== 0) {
        Drupal::configFactory()
          ->getEditable($key)
          ->delete();
        $config_deteted = TRUE;
      }
    }
  }

  // Get the user selected configs in optional folder and delete.
  $opt_configs = $form_state
    ->getValue('opt_configs') ? $form_state
    ->getValue('opt_configs') : [];
  if ($form_state
    ->getValue('opt_all_configs') != 0) {
    foreach ($opt_configs as $key => $value) {
      Drupal::configFactory()
        ->getEditable($key)
        ->delete();
    }
    $config_deteted = TRUE;
  }
  else {
    foreach ($opt_configs as $key => $values) {
      if ($values !== 0) {
        Drupal::configFactory()
          ->getEditable($key)
          ->delete();
        $config_deteted = TRUE;
      }
    }
  }
  if ($config_deteted) {
    \Drupal::messenger()
      ->addMessage(t('The selected modules have been uninstalled and configurations
         deleted'));
  }
  else {
    \Drupal::messenger()
      ->addMessage(t('The selected modules have been uninstalled'));
  }
  $redirect = new Url('system.modules_uninstall');
  $form_state
    ->setRedirectUrl($redirect);
}