function _install_config_locale_overrides

Same name in other branches
  1. 10 core/includes/install.core.inc \_install_config_locale_overrides()
  2. 11.x core/includes/install.core.inc \_install_config_locale_overrides()

Creates a batch to process config translations after installing from config.

This ensures that the logic from LocaleConfigSubscriber::onConfigSave() is run on sites after installing from configuration so updating translations from PO files does not result in overwriting customizations.

Return value

array The batch definition.

See also

\Drupal\locale\LocaleConfigSubscriber::onConfigSave()

1 call to _install_config_locale_overrides()
install_finish_translations in core/includes/install.core.inc
Finishes importing files at end of installation.

File

core/includes/install.core.inc, line 2469

Code

function _install_config_locale_overrides() {
    // @todo https://www.drupal.org/project/drupal/issues/3252244 Somehow the
    //   config cache gets filled up with junk after installing from
    //   configuration.
    \Drupal::service('cache.config')->deleteAll();
    // Get the services we need.
    $language_manager = \Drupal::languageManager();
    
    /** @var \Drupal\locale\LocaleConfigManager $locale_config_manager */
    $locale_config_manager = \Drupal::service('locale.config_manager');
    $langcodes = array_keys($language_manager->getLanguages());
    if (count($langcodes) > 1 && !$language_manager instanceof ConfigurableLanguageManagerInterface) {
        throw new \LogicException('There are multiple languages and the language manager is not an instance of ConfigurableLanguageManagerInterface');
    }
    $batch_builder = (new BatchBuilder())->setFile('core/includes/install.core.inc')
        ->setTitle(t('Updating configuration translations'))
        ->setInitMessage(t('Starting configuration update'))
        ->setErrorMessage(t('Error updating configuration translations'));
    $i = 0;
    $batch_names = [];
    foreach ($locale_config_manager->getComponentNames() 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('_install_config_locale_overrides_process_batch', [
                $batch_names,
                $langcodes,
            ]);
            $batch_names = [];
        }
    }
    if (!empty($batch_names)) {
        $batch_builder->addOperation('_install_config_locale_overrides_process_batch', [
            $batch_names,
            $langcodes,
        ]);
    }
    return $batch_builder->toArray();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.