You are here

public function SiteConfigureForm::submitForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Installer/Form/SiteConfigureForm.php \Drupal\Core\Installer\Form\SiteConfigureForm::submitForm()

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 ConfigFormBase::submitForm

File

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

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'))
      ->set('country.default', (string) $form_state
      ->getValue('site_default_country'))
      ->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 precreated user 1 with placeholder values. Let's save the real values.
  $account = $this->userStorage
    ->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'];
  $account
    ->save();
}