diff --git a/core/lib/Drupal/Core/Config/ConfigInstallerEvent.php b/core/lib/Drupal/Core/Config/ConfigInstallerEvent.php index 88d7996..e69de29 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstallerEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigInstallerEvent.php @@ -1,61 +0,0 @@ -name = $name; - $this->collection = $collection; - } - - /** - * Gets the config name. - * - * @return string - * The configuration name. - */ - public function getName() { - return $this->name; - } - - /** - * Gets the config collection name. - * - * @return string - * The collection name. - */ - public function getCollection() { - return $this->collection; - } - -} diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index bcf140e..9943889 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -314,6 +314,7 @@ function locale_get_plural($count, $langcode = NULL) { */ function locale_modules_installed($modules) { $components['module'] = $modules; + locale_system_set_config_langcodes($components); locale_system_update($components); } @@ -330,6 +331,7 @@ function locale_module_preuninstall($module) { */ function locale_themes_installed($themes) { $components['theme'] = $themes; + locale_system_set_config_langcodes($components); locale_system_update($components); } @@ -357,6 +359,38 @@ function locale_cron() { } /** + * Update default configuration when new modules or themes are installed. + * + * @param array $components + * An array of arrays of component (theme and/or module) names to import + * translations for, indexed by type. + */ +function locale_system_set_config_langcodes(array $components) { + $default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId(); + if ($default_langcode != 'en') { + $components += array('module' => array(), 'theme' => array()); + $list = array_merge($components['module'], $components['theme']); + + // If just installed the locale module, we need to update all prior + // shipped configuration to the foreign site language. Otherwise just update + // the shipped configuration just imported. + $names = Locale::config()->getComponentNames(in_array('locale', $list) ? array() : $list); + + foreach ($names as $name) { + $config = \Drupal::configFactory()->getEditable($name); + // Should only update if still exists in active configuration. If locale + // module is enabled later, then some configuration may not exist anymore. + if (!$config->isNew()) { + $langcode = $config->get('langcode'); + if (empty($langcode) || $langcode == 'en') { + $config->set('langcode', $default_langcode)->save(); + } + } + } + } +} + +/** * Imports translations when new modules or themes are installed. * * This function will start a batch to import translations for the added diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index c98e6a4..c9ec321 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -254,7 +254,7 @@ public function deleteTranslationOverride($name, $langcode) { * @return array * Array of configuration object names. */ - public function getComponentNames(array $components) { + public function getComponentNames(array $components = array()) { $components = array_filter($components); if ($components) { $names = array(); diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index 94e3edb..711eaf2 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -82,38 +82,10 @@ public function __construct(StringStorageInterface $string_storage, ConfigFactor public static function getSubscribedEvents() { $events[LanguageConfigOverrideEvents::SAVE_OVERRIDE] = 'onOverrideSave'; $events[LanguageConfigOverrideEvents::DELETE_OVERRIDE] = 'onOverrideDelete'; - $events[ConfigEvents::INSTALL] = 'onConfigInstall'; return $events; } /** - * Updates just installed default configuration to reflect site language. - * - * @param \Drupal\Core\Config\ConfigInstallerEvent $event - */ - public function onConfigInstall(ConfigInstallerEvent $event) { - $site_langcode = $this->languageManager->getDefaultLanguage()->getId(); - // Should only rewrite default configuration if the site is not English by - // default. - if ($site_langcode != 'en') { - $collection = $event->getCollection(); - // Should only rewrite default configuration in the default collection. - if ($collection == StorageInterface::DEFAULT_COLLECTION) { - $name = $event->getName(); - $config = $this->configFactory->getEditable($name); - $default_langcode = $config->get('langcode') ?: 'en'; - // Should only rewrite default configuration if it is in English. - if ($default_langcode == 'en') { - // Just need to change the language code of the active configuration. - // LocaleConfigManager is later responsible to merge in the proper - // translations for each translatable piece and keep it up to date. - $config->set('langcode', $site_langcode)->save(); - } - } - } - } - - /** * Updates the translation strings when shipped configuration is saved. * * @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event diff --git a/core/lib/Drupal/Core/Config/ConfigEvents.php b/core/lib/Drupal/Core/Config/ConfigEvents.php index 082a0dd..0ba9075 100644 --- a/core/lib/Drupal/Core/Config/ConfigEvents.php +++ b/core/lib/Drupal/Core/Config/ConfigEvents.php @@ -99,22 +99,6 @@ const IMPORT = 'config.importer.import'; /** - * Name of the event fired when installing configuration to target storage. - * - * This event allows modules to perform additional actions when configuration - * is installer. The event listener method receives a - * \Drupal\Core\Config\ConfigInstallerEvent instance. - * - * @Event - * - * @see \Drupal\Core\Config\ConfigInstallerEvent - * @see \Drupal\Core\Config\ConfigInstaller::createConfiguration(). - * - * @var string - */ - const INSTALL = 'config.install'; - - /** * Name of event fired to collect information on all config collections. * * This event allows modules to add to the list of configuration collections diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 44f70d3..8065613 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -239,7 +239,6 @@ protected function createConfiguration($collection, array $config_to_install) { else { $new_config->save(); } - $this->eventDispatcher->dispatch(ConfigEvents::INSTALL, new ConfigInstallerEvent($name, $collection)); } }