diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 4729316..9a91adc 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -293,25 +293,6 @@ function language_negotiation_url_prefixes() { } /** - * Update the list of prefixes from the installed languages. - */ -function language_negotiation_url_prefixes_update() { - $config = \Drupal::configFactory()->getEditable('language.negotiation'); - $prefixes = $config->get('url.prefixes'); - foreach (\Drupal::languageManager()->getLanguages() as $language) { - // The prefix for this language should be updated if it's not assigned yet - // or the prefix is set to the empty string. - if (empty($prefixes[$language->getId()])) { - // For the default language, set the prefix to the empty string, - // otherwise use the langcode. - $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId(); - } - // Otherwise we keep the configured prefix. - } - $config->set('url.prefixes', $prefixes)->save(); -} - -/** * Reads language domains. * * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index 89cc167..a153423 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -133,7 +133,7 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // Update URL Prefixes for all languages after the // LanguageManagerInterface::getLanguages() cache is flushed. - language_negotiation_url_prefixes_update(); + self::updateAllUrlPrefixes(); // If after adding this language the site will become multilingual, we need // to rebuild language services. @@ -266,4 +266,23 @@ public static function createFromLangcode($langcode) { } } + /** + * Update the list of prefixes from the installed languages. + */ + static function updateAllUrlPrefixes() { + $config = \Drupal::configFactory()->getEditable('language.negotiation'); + $prefixes = $config->get('url.prefixes'); + foreach (\Drupal::languageManager()->getLanguages() as $language) { + // The prefix for this language should be updated if it's not assigned yet + // or the prefix is set to the empty string. + if (empty($prefixes[$language->getId()])) { + // For the default language, set the prefix to the empty string, + // otherwise use the langcode. + $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId(); + } + // Otherwise we keep the configured prefix. + } + $config->set('url.prefixes', $prefixes)->save(); + } + } diff --git a/core/modules/language/src/EventSubscriber/ConfigSubscriber.php b/core/modules/language/src/EventSubscriber/ConfigSubscriber.php index e1875ce..ccfd3dd 100644 --- a/core/modules/language/src/EventSubscriber/ConfigSubscriber.php +++ b/core/modules/language/src/EventSubscriber/ConfigSubscriber.php @@ -80,8 +80,7 @@ public function onConfigSave(ConfigCrudEvent $event) { $this->languageDefault->set(new Language($default_language->get())); $this->languageManager->reset(); - // Directly update language negotiation settings instead of calling - // language_negotiation_url_prefixes_update() to ensure that the code + // Directly update language negotiation settings to ensure that the code // obeys the hook_update_N() restrictions. $negotiation_config = $this->configFactory->getEditable('language.negotiation'); $negotiation_changed = FALSE;