diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 555b425..aac3c65 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -27,9 +27,11 @@ class LanguageManager implements LanguageManagerInterface { protected $translation; /** - * An array of arrays the available languages keyed by language code. The top - * level array is keyed by the language the language names are translated in. - * The next level is keyed by the flags provided to self::getLanguages(). + * A static cache of translated language lists. + * + * Array of arrays to cache the result of self::getLanguages() keyed by the + * language the list is translated to (first level) and the flags provided to + * the method (second level). * * @var \Drupal\Core\Language\LanguageInterface[] * @@ -140,10 +142,11 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { // The default language and locked languages comprise the full language // list. $default = $this->getDefaultLanguage(); - $this->languages[$static_cache_id][$flags] = array($default->getId() => $default); - $this->languages[$static_cache_id][$flags] += $this->getDefaultLockedLanguages($default->getWeight()); + $languages = array($default->getId() => $default); + $languages += $this->getDefaultLockedLanguages($default->getWeight()); + // Filter the full list of languages based on the value of $flags. - $this->languages[$static_cache_id][$flags] = $this->filterLanguages($this->languages[$static_cache_id][$flags], $flags); + $this->languages[$static_cache_id][$flags] = $this->filterLanguages($languages, $flags); } return $this->languages[$static_cache_id][$flags]; } diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 0746696..32429e5 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -278,24 +278,22 @@ public function setNegotiator(LanguageNegotiatorInterface $negotiator) { * {@inheritdoc} */ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { - // If a config override is set cache using that language's ID. + // If a config override is set, cache using that language's ID. if ($override_language = $this->getConfigOverrideLanguage()) { $static_cache_id = $override_language->getId(); } else { $static_cache_id = $this->getCurrentLanguage()->getId(); } - if (!isset($this->languages[$static_cache_id][$flags])) { + if (!isset($this->languages[$static_cache_id][$flags])) { // Initialize the language list with the default language and default // locked languages. These cannot be removed. This serves as a fallback // list if this method is invoked while the language module is installed // and the configuration entities for languages are not yet fully imported. $default = $this->getDefaultLanguage(); - $this->languages[$static_cache_id][$flags] = array($default->getId() => $default); - $this->languages[$static_cache_id][$flags] += $this->getDefaultLockedLanguages($default->getWeight()); - // Filter the full list of languages based on the value of $flags. - $this->languages[$static_cache_id][$flags] = $this->filterLanguages($this->languages[$static_cache_id][$flags], $flags); + $languages = array($default->getId() => $default); + $languages += $this->getDefaultLockedLanguages($default->getWeight()); // Load configurable languages on top of the defaults. Ideally this could // use the entity API to load and instantiate ConfigurableLanguage objects. @@ -310,11 +308,14 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { foreach ($this->configFactory->loadMultiple($config_ids) as $config) { $data = $config->get(); $data['name'] = $data['label']; - $this->languages[$static_cache_id][$flags][$data['id']] = new Language($data); + $languages[$data['id']] = new Language($data); } - Language::sort($this->languages[$static_cache_id][$flags]); - $this->languages[$static_cache_id][$flags] = $this->filterLanguages($this->languages[$static_cache_id][$flags], $flags); + Language::sort($languages); + + // Filter the full list of languages based on the value of $flags. + $this->languages[$static_cache_id][$flags] = $this->filterLanguages($languages, $flags); } + return $this->languages[$static_cache_id][$flags]; }