You are here

function install_config_revert_install_changes in Drupal 9

Same name and namespace in other branches
  1. 8 core/includes/install.core.inc \install_config_revert_install_changes()
  2. 10 core/includes/install.core.inc \install_config_revert_install_changes()

Reverts configuration if hook_install() implementations have made changes.

This step ensures that the final configuration matches the configuration provided to the installer.

File

core/includes/install.core.inc, line 2396
API functions for installing Drupal.

Code

function install_config_revert_install_changes() {
  global $install_state;
  $storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'));
  $storage_comparer
    ->createChangelist();
  if ($storage_comparer
    ->hasChanges()) {
    $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::service('lock.persistent'), \Drupal::service('config.typed'), \Drupal::service('module_handler'), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'), \Drupal::service('extension.list.module'));
    try {
      $config_importer
        ->import();
    } catch (ConfigImporterException $e) {
      global $install_state;
      $messenger = \Drupal::messenger();

      // There are validation errors.
      $messenger
        ->addError(t('The configuration synchronization failed validation.'));
      foreach ($config_importer
        ->getErrors() as $message) {
        $messenger
          ->addError($message);
      }
      install_display_output([
        '#title' => t('Configuration validation'),
      ], $install_state);
    }

    // At this point the configuration should match completely.
    if (\Drupal::moduleHandler()
      ->moduleExists('language')) {

      // If the English language exists at this point we need to ensure
      // install_download_additional_translations_operations() does not delete
      // it.
      if (ConfigurableLanguage::load('en')) {
        $install_state['profile_info']['keep_english'] = TRUE;
      }
    }
  }
}