ModulesListForm::submitForm

public ModulesListForm::submitForm(array &$form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

core/modules/system/src/Form/ModulesListForm.php, line 427

Class

ModulesListForm
Provides module installation interface.

Namespace

Drupal\system\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  // Retrieve a list of modules to install and their dependencies.
  $modules = $this->buildModuleList($form_state);

  // Redirect to a confirmation form if needed.
  if (!empty($modules['experimental']) || !empty($modules['dependencies'])) {

    $route_name = !empty($modules['experimental']) ? 'system.modules_list_experimental_confirm' : 'system.modules_list_confirm';
    // Write the list of changed module states into a key value store.
    $account = $this->currentUser()->id();
    $this->keyValueExpirable->setWithExpire($account, $modules, 60);

    // Redirect to the confirmation form.
    $form_state->setRedirect($route_name);

    // We can exit here because at least one modules has dependencies
    // which we have to prompt the user for in a confirmation form.
    return;
  }

  // Install the given modules.
  if (!empty($modules['install'])) {
    try {
      $this->moduleInstaller->install(array_keys($modules['install']));
      $module_names = array_values($modules['install']);
      drupal_set_message($this->formatPlural(count($module_names), 'Module %name has been enabled.', '@count modules have been enabled: %names.', array(
        '%name' => $module_names[0],
        '%names' => implode(', ', $module_names),
      )));
    }
    catch (PreExistingConfigException $e) {
      $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
      drupal_set_message(
      $this->formatPlural(
      count($config_objects), 
      'Unable to install @extension, %config_names already exists in active configuration.', 
      'Unable to install @extension, %config_names already exist in active configuration.', 
      array(
        '%config_names' => implode(', ', $config_objects),
        '@extension' => $modules['install'][$e->getExtension()]
      )), 
      'error'
      );
      return;
    }
    catch (UnmetDependenciesException $e) {
      drupal_set_message(
      $e->getTranslatedMessage($this->getStringTranslation(), $modules['install'][$e->getExtension()]), 
      'error'
      );
      return;
    }
  }
}
doc_Drupal
2016-10-29 09:29:38
Comments
Leave a Comment

Please login to continue.