function config_install_batch in Configuration installer 8
Creates a batch for the config importer to process.
See also
config_installer_install_tasks_alter()
File
- ./
config_installer.profile, line 55 - Enables modules and site configuration for a minimal site installation.
Code
function config_install_batch() {
// We need to manually trigger the installation of core-provided entity types,
// as those will not be handled by the module installer.
// @see install_profile_modules()
install_core_entity_type_definitions();
// Create a source storage that reads from sync.
$listing = new \Drupal\Core\Extension\ExtensionDiscovery(\Drupal::root());
$listing
->setProfileDirectories([]);
$sync = new SourceStorage(\Drupal::service('config.storage.sync'), $listing
->scan('profile'));
// Match up the site uuids, the install_base_system install task will have
// installed the system module and created a new UUID.
$system_site = $sync
->read('system.site');
\Drupal::configFactory()
->getEditable('system.site')
->set('uuid', $system_site['uuid'])
->save();
// Create the storage comparer and the config importer.
$config_manager = \Drupal::service('config.manager');
$storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'), $config_manager);
$storage_comparer
->createChangelist();
$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 {
$sync_steps = $config_importer
->initialize();
// Implementing hook_config_import_steps_alter() in this file does not work
// if using the 'drush site-install' command. Add the step to fix the import
// profile before the last step of the configuration import.
$last = array_pop($sync_steps);
$sync_steps[] = 'config_installer_install_uninstalled_profile_dependencies';
$sync_steps[] = 'config_installer_config_import_profile';
$sync_steps[] = $last;
$batch = [
'operations' => [],
'finished' => 'config_install_batch_finish',
'title' => t('Synchronizing configuration'),
'init_message' => t('Starting configuration synchronization.'),
'progress_message' => t('Completed @current step of @total.'),
'error_message' => t('Configuration synchronization has encountered an error.'),
'file' => drupal_get_path('module', 'config') . '/config.admin.inc',
];
foreach ($sync_steps as $sync_step) {
$batch['operations'][] = [
'config_install_batch_process',
[
$config_importer,
$sync_step,
],
];
}
return $batch;
} 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');
}
}
}