function SiteConfigureForm::submitForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php \Drupal\Core\Installer\Form\SiteConfigureForm::submitForm()
  2. 8.9.x core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php \Drupal\Core\Installer\Form\SiteConfigureForm::submitForm()
  3. 10 core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php \Drupal\Core\Installer\Form\SiteConfigureForm::submitForm()

Overrides ConfigFormBase::submitForm

File

core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php, line 234

Class

SiteConfigureForm
Provides the site configuration form.

Namespace

Drupal\Core\Installer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
    global $install_state;
    if (empty($install_state['config_install_path'])) {
        $this->config('system.site')
            ->set('name', (string) $form_state->getValue('site_name'))
            ->set('mail', (string) $form_state->getValue('site_mail'))
            ->save(TRUE);
        $this->config('system.date')
            ->set('timezone.default', (string) $form_state->getValue('date_default_timezone'))
            ->save(TRUE);
    }
    $account_values = $form_state->getValue('account');
    // Enable update.module if this option was selected.
    $update_status_module = $form_state->getValue('enable_update_status_module');
    if (empty($install_state['config_install_path']) && $update_status_module) {
        $this->moduleInstaller
            ->install([
            'update',
        ]);
        // Add the site maintenance account's email address to the list of
        // addresses to be notified when updates are available, if selected.
        $email_update_status_emails = $form_state->getValue('enable_update_status_emails');
        if ($email_update_status_emails) {
            // Reset the configuration factory so it is updated with the new module.
            $this->resetConfigFactory();
            $this->config('update.settings')
                ->set('notification.emails', [
                $account_values['mail'],
            ])
                ->save(TRUE);
        }
    }
    // We created user 1 with placeholder values. Let's save the real values.
    
    /** @var \Drupal\user\UserInterface $account */
    $account = $this->entityTypeManager
        ->getStorage('user')
        ->load(1);
    $account->init = $account->mail = $account_values['mail'];
    $account->roles = $account->getRoles();
    $account->activate();
    $account->timezone = $form_state->getValue('date_default_timezone');
    $account->pass = $account_values['pass'];
    $account->name = $account_values['name'];
    // Ensure user 1 has an administrator role if one exists.
    
    /** @var \Drupal\user\RoleInterface[] $admin_roles */
    $admin_roles = $this->getAdminRoles();
    if (count(array_intersect($account->getRoles(), array_keys($admin_roles))) === 0) {
        if (count($admin_roles) > 0) {
            foreach ($admin_roles as $role) {
                $account->addRole($role->id());
            }
        }
        elseif ($this->superUserAccessPolicy === FALSE) {
            $this->messenger()
                ->addWarning($this->t('The user %username does not have administrator access. For more information, see the documentation on <a href="@secure-user-1-docs">securing the admin super user</a>.', [
                '%username' => $account->getDisplayName(),
                '@secure-user-1-docs' => 'https://www.drupal.org/docs/administering-a-drupal-site/security-in-drupal/securing-the-admin-super-user-1#s-disable-the-super-user-access-policy',
            ]));
        }
    }
    $account->save();
}

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