You are here

function config_installer_fix_profile in Configuration installer 8

Fixes configuration if the install profile has made changes in hook_install().

See also

config_installer_install_tasks_alter()

File

./config_installer.profile, line 244
Enables modules and site configuration for a minimal site installation.

Code

function config_installer_fix_profile() {
  global $install_state;

  // It is possible that installing the profile makes unintended configuration
  // changes.
  $config_manager = \Drupal::service('config.manager');
  $storage_comparer = new StorageComparer(\Drupal::service('config.storage.sync'), \Drupal::service('config.storage'), $config_manager);
  $storage_comparer
    ->createChangelist();
  if ($storage_comparer
    ->hasChanges()) {

    // Swap out the install profile so that the profile module exists.
    _config_installer_switch_profile(_config_installer_get_original_install_profile());
    system_list_reset();
    $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), $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'));
    try {
      $config_importer
        ->import();
    } catch (ConfigImporterException $e) {

      // There are validation errors.
      drupal_set_message(\Drupal::translation()
        ->translate('The configuration synchronization failed validation.'));
      foreach ($config_importer
        ->getErrors() as $message) {
        drupal_set_message($message, 'error');
      }
    }

    // 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 (\Drupal\language\Entity\ConfigurableLanguage::load('en')) {
        $install_state['profile_info']['keep_english'] = TRUE;
      }
    }

    // Replace the install profile so that the config_installer still works.
    _config_installer_switch_profile('config_installer');
    system_list_reset();
  }
}