function SiteSettingsForm::submitForm

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

Overrides FormInterface::submitForm

File

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

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;
    // Make sure the install API is available.
    include_once DRUPAL_ROOT . '/core/includes/install.inc';
    // Update global settings array and save.
    $settings = [];
    // For BC, just save the database driver name, not the database driver
    // extension name which equals the driver's namespace.
    $database = $form_state->get('database');
    $namespaceParts = explode('\\', $database['driver']);
    $database['driver'] = end($namespaceParts);
    $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,
        ];
    }
    SettingsEditor::rewrite($this->sitePath . '/settings.php', $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();
}

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