diff --git a/core/modules/taxonomy/src/Plugin/Field/FieldFormatter/TaxonomyFormatterBase.php b/core/modules/taxonomy/src/Plugin/Field/FieldFormatter/TaxonomyFormatterBase.php index 83e5ef4..8343d3d 100644 --- a/core/modules/taxonomy/src/Plugin/Field/FieldFormatter/TaxonomyFormatterBase.php +++ b/core/modules/taxonomy/src/Plugin/Field/FieldFormatter/TaxonomyFormatterBase.php @@ -24,10 +24,12 @@ public function prepareView(array $entities_items) { $terms = array(); // Collect every possible term attached to any of the fieldable entities. - /** @var \Drupal\Core\Field\EntityReferenceFieldItemList $items */ + /* @var \Drupal\Core\Field\EntityReferenceFieldItemList $items */ foreach ($entities_items as $items) { - $active_langcode = $items->getParent()->language()->id; - /** @var \Drupal\taxonomy\Entity\Term $term */ + /* @var \Drupal\Core\Entity\ContentEntityBase $parent */ + $parent = $items->getParent(); + $active_langcode = $parent->language()->getId(); + /* @var \Drupal\taxonomy\Entity\Term $term */ foreach ($items->referencedEntities() as $term) { if ($term->hasTranslation($active_langcode)) { $translated_term = $term->getTranslation($active_langcode); diff --git a/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php b/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php index f199bf3..0e92917 100644 --- a/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php +++ b/core/modules/taxonomy/src/Tests/TermTranslationFieldViewTest.php @@ -84,6 +84,7 @@ protected function setUp() { parent::setUp(); $this->setupLanguages(); $this->vocabulary = $this->createVocabulary(); + $this->enableTranslation(); $this->setUpTerm(); $this->setUpTermReferenceField(); $this->setUpNode(); @@ -92,7 +93,7 @@ protected function setUp() { /** * Tests if the translated taxonomy term is displayed. */ - public function testTranslatedTaxonomyTermreferenceDisplay() { + public function testTranslatedTaxonomyTermReferenceDisplay() { $path = 'node/' . $this->node->id(); $translation_path = $this->translateToLangcode . '/' . $path; @@ -139,7 +140,7 @@ protected function enableTranslation() { // Enable translation for the current entity type and ensure the change is // picked up. content_translation_set_config('node', 'article', 'enabled', TRUE); - content_translation_set_config('taxonomy', $this->vocabulary, 'enabled', TRUE); + content_translation_set_config('taxonomy', $this->vocabulary->id(), 'enabled', TRUE); drupal_static_reset(); \Drupal::entityManager()->clearCachedDefinitions(); \Drupal::service('router.builder')->rebuild(); @@ -197,4 +198,5 @@ protected function setUpTermReferenceField() { )) ->save(); } + }