ModulesListConfirmForm::submitForm

public ModulesListConfirmForm::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/ModulesListConfirmForm.php, line 159

Class

ModulesListConfirmForm
Builds a confirmation form for enabling modules with dependencies.

Namespace

Drupal\system\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  // Remove the key value store entry.
  $account = $this->currentUser()->id();
  $this->keyValueExpirable->delete($account);

  if (!empty($this->modules['install'])) {
    // Don't catch the exception that this can throw for missing dependencies:
    // the form doesn't allow modules with unmet dependencies, so the only way
    // this can happen is if the filesystem changed between form display and
    // submit, in which case the user has bigger problems.
    try {
      // Install the given modules.
      $this->moduleInstaller->install(array_keys($this->modules['install']));
    }
    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' => $this->modules['install'][$e->getExtension()]
      )), 
      'error'
      );
      return;
    }
    catch (UnmetDependenciesException $e) {
      drupal_set_message(
      $e->getTranslatedMessage($this->getStringTranslation(), $this->modules['install'][$e->getExtension()]), 
      'error'
      );
      return;
    }

    $module_names = array_values($this->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),
    )));
  }

  $form_state->setRedirectUrl($this->getCancelUrl());
}
doc_Drupal
2016-10-29 09:29:32
Comments
Leave a Comment

Please login to continue.