function ModulesListForm::submitForm

Same name and namespace in other branches
  1. 9 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::submitForm()
  2. 8.9.x core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::submitForm()
  3. 10 core/modules/system/src/Form/ModulesListForm.php \Drupal\system\Form\ModulesListForm::submitForm()

Overrides FormInterface::submitForm

File

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

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['non_stable']) || !empty($modules['dependencies'])) {
        $route_name = !empty($modules['non_stable']) ? 'system.modules_list_non_stable_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']));
            $this->messenger()
                ->addStatus($this->modulesEnabledConfirmationMessage($modules['install']));
        } catch (PreExistingConfigException $e) {
            $this->messenger()
                ->addError($this->modulesFailToEnableMessage($modules, $e));
            return;
        } catch (UnmetDependenciesException $e) {
            $this->messenger()
                ->addError($e->getTranslatedMessage($this->getStringTranslation(), $modules['install'][$e->getExtension()]));
            return;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.