function locale_config_batch_build in Drupal 9
Same name and namespace in other branches
- 8 core/modules/locale/locale.bulk.inc \locale_config_batch_build()
Creates a locale batch to refresh specific configuration.
Parameters
array $names: List of configuration object names (which are strings) to update.
array $langcodes: List of language codes to refresh.
array $options: (optional) An array with options that can have the following elements:
- 'finish_feedback': Whether or not to give feedback to the user when the batch is finished. Defaults to TRUE.
Return value
array The batch definition.
See also
locale_config_batch_refresh_name()
1 call to locale_config_batch_build()
- locale_config_batch_update_components in core/
modules/ locale/ locale.bulk.inc - Builds a locale batch to refresh configuration.
File
- core/
modules/ locale/ locale.bulk.inc, line 567 - Mass import-export and batch import functionality for Gettext .po files.
Code
function locale_config_batch_build(array $names, array $langcodes, array $options = []) {
$options += [
'finish_feedback' => TRUE,
];
$batch_builder = (new BatchBuilder())
->setFile(\Drupal::service('extension.list.module')
->getPath('locale') . '/locale.bulk.inc')
->setTitle(t('Updating configuration translations'))
->setInitMessage(t('Starting configuration update'))
->setErrorMessage(t('Error updating configuration translations'));
$i = 0;
$batch_names = [];
foreach ($names as $name) {
$batch_names[] = $name;
$i++;
// During installation the caching of configuration objects is disabled so
// it is very expensive to initialize the \Drupal::config() object on each
// request. We batch a small number of configuration object upgrades
// together to improve the overall performance of the process.
if ($i % 20 == 0) {
$batch_builder
->addOperation('locale_config_batch_refresh_name', [
$batch_names,
$langcodes,
]);
$batch_names = [];
}
}
if (!empty($batch_names)) {
$batch_builder
->addOperation('locale_config_batch_refresh_name', [
$batch_names,
$langcodes,
]);
}
if (!empty($options['finish_feedback'])) {
$batch_builder
->setFinishCallback('locale_config_batch_finished');
}
return $batch_builder
->toArray();
}