You are here

protected function SiteSettingsForm::getDatabaseErrors in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php \Drupal\Core\Installer\Form\SiteSettingsForm::getDatabaseErrors()
  2. 10 core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php \Drupal\Core\Installer\Form\SiteSettingsForm::getDatabaseErrors()

Get any database errors and links them to a form element.

Parameters

array $database: An array of database settings.

string $settings_file: The settings file that contains the database settings.

Return value

array An array of form errors keyed by the element name and parents.

1 call to SiteSettingsForm::getDatabaseErrors()
SiteSettingsForm::validateForm in core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php
Form validation handler.

File

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

Class

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

Namespace

Drupal\Core\Installer\Form

Code

protected function getDatabaseErrors(array $database, $settings_file) {
  $errors = install_database_errors($database, $settings_file);
  $form_errors = array_filter($errors, function ($value) {

    // Errors keyed by something other than an integer already are linked to
    // form elements.
    return is_int($value);
  });

  // Find the generic errors.
  $errors = array_diff_key($errors, $form_errors);
  if (count($errors)) {
    $error_message = static::getDatabaseErrorsTemplate($errors);

    // These are generic errors, so we do not have any specific key of the
    // database connection array to attach them to; therefore, we just put
    // them in the error array with standard numeric keys.
    $form_errors[$database['driver'] . '][0'] = $this->renderer
      ->renderPlain($error_message);
  }
  return $form_errors;
}