diff --git a/core/modules/comment/tests/modules/comment_test/comment_test.module b/core/modules/comment/tests/modules/comment_test/comment_test.module index 3f9f9a4..9fb600f 100644 --- a/core/modules/comment/tests/modules/comment_test/comment_test.module +++ b/core/modules/comment/tests/modules/comment_test/comment_test.module @@ -13,22 +13,12 @@ * Implements hook_entity_type_alter(). */ function comment_test_entity_type_alter(array &$entity_types) { - static $invoked = FALSE; - /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - if (!$invoked) { - // Avoid infinite loops. ConfigurableLanguageManager::getLanguages() - // that isMultilingual() uses will use the entity API to load languages - // which will result in calling this hook again. - $invoked = TRUE; - if (\Drupal::languageManager()->isMultilingual()) { - // Allow further hook invocations to alter entities. - $invoked = FALSE; - // Enable language handling for comment fields. - $translation = $entity_types['comment']->get('translation'); - $translation['comment_test'] = TRUE; - $entity_types['comment']->set('translation', $translation); - } + if (\Drupal::languageManager()->isMultilingual()) { + // Enable language handling for comment fields. + $translation = $entity_types['comment']->get('translation'); + $translation['comment_test'] = TRUE; + $entity_types['comment']->set('translation', $translation); } } diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index a4c454c..6826917 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -7,7 +7,6 @@ namespace Drupal\language; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PhpStorage\PhpStorageFactory; use Drupal\Core\Config\ConfigFactoryInterface; @@ -18,7 +17,6 @@ use Drupal\Core\Url; use Drupal\language\Config\LanguageConfigFactoryOverrideInterface; use Drupal\language\Entity\ConfigurableLanguage; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -279,22 +277,29 @@ public function setNegotiator(LanguageNegotiatorInterface $negotiator) { * {@inheritdoc} */ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { - $languages = array(); - - try { - // Use languages from configuration if possible. - $languages = entity_load_multiple('configurable_language'); - Language::sort($languages); - } - catch (PluginNotFoundException $e) { - // If the language module is being installed, the entity type may not be - // available yet. + // 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. + $languages = parent::getLanguages($flags); + + // Load configurable languages on top of the defaults. Ideally this could + // use the entity API to load and instantiate ConfigurableLanguage objects. + // However the entity API depends on the language system, so that would + // result in infinite loops. We use the configuration system directly and + // instantiate runtime Language objects. When language entities are imported + // those cover the default and locked languages, so site-specific + // configuration will prevail over the fallback values. Having them in the + // array already ensures if this is invoked in the middle of importing + // language configuration entities, the defaults are always present. + $config_ids = $this->configFactory->listAll('language.entity.'); + foreach ($this->configFactory->loadMultiple($config_ids) as $config) { + $data = $config->get(); + $data['name'] = $data['label']; + $languages[$data['id']] = new Language($data); } - - // If there are no languages in the list, either the entity type or the - // default configuration is not yet installed. Degrade gracefully to the - // default language list. - return empty($languages) ? parent::getLanguages($flags) : $this->filterLanguages($languages, $flags); + Language::sort($languages); + return $this->filterLanguages($languages, $flags); } /**