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 9fb600f..3f9f9a4 100644 --- a/core/modules/comment/tests/modules/comment_test/comment_test.module +++ b/core/modules/comment/tests/modules/comment_test/comment_test.module @@ -13,12 +13,22 @@ * 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 (\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); + 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); + } } }