You are here

public function SiteSettingsForm::submitForm in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php \Drupal\Core\Installer\Form\SiteSettingsForm::submitForm()
  2. 9 core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php \Drupal\Core\Installer\Form\SiteSettingsForm::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 FormInterface::submitForm

File

core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php, line 235

Class

SiteSettingsForm
Provides a form to configure and rewrite settings.php.

Namespace

Drupal\Core\Installer\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  global $install_state;

  // Update global settings array and save.
  $settings = [];
  $database = $form_state
    ->get('database');
  $settings['databases']['default']['default'] = (object) [
    'value' => $database,
    'required' => TRUE,
  ];
  $settings['settings']['hash_salt'] = (object) [
    'value' => Crypt::randomBytesBase64(55),
    'required' => TRUE,
  ];

  // If settings.php does not contain a config sync directory name we need to
  // configure one.
  if (empty(Settings::get('config_sync_directory'))) {
    if (empty($install_state['config_install_path'])) {

      // Add a randomized config directory name to settings.php
      $config_sync_directory = $this
        ->createRandomConfigDirectory();
    }
    else {

      // Install profiles can contain a config sync directory. If they do,
      // 'config_install_path' is a path to the directory.
      $config_sync_directory = $install_state['config_install_path'];
    }
    $settings['settings']['config_sync_directory'] = (object) [
      'value' => $config_sync_directory,
      'required' => TRUE,
    ];
  }
  drupal_rewrite_settings($settings);

  // Indicate that the settings file has been verified, and check the database
  // for the last completed task, now that we have a valid connection. This
  // last step is important since we want to trigger an error if the new
  // database already has Drupal installed.
  $install_state['settings_verified'] = TRUE;
  $install_state['config_verified'] = TRUE;
  $install_state['database_verified'] = TRUE;
  $install_state['completed_task'] = install_verify_completed_task();
}