diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php b/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php index 684b56f..c3f635b 100644 --- a/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php +++ b/core/modules/entity_reference/src/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php @@ -8,6 +8,7 @@ namespace Drupal\entity_reference\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FormatterBase; +use Drupal\Core\TypedData\TranslatableInterface; /** * Parent plugin for entity reference formatters. @@ -60,7 +61,7 @@ public function prepareView(array $entities_items) { $rekey = FALSE; /* @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter $parent */ $parent = $items->getParent(); - /* @var \Drupal\Core\Entity\ContentEntityBase $entity */ + /* @var \Drupal\Core\Entity\ContentEntityBase $target_entity */ $parent_entity = $parent->getValue(); $active_langcode = $parent_entity->language()->getId(); foreach ($items as $item) { @@ -73,20 +74,24 @@ public function prepareView(array $entities_items) { $rekey = TRUE; continue; } + } + else { + // This is an "auto_create" item, just leave the entity in place. + } + $target_entity = $target_entities[$identifier]; + if ($target_entity instanceof TranslatableInterface) { /* @var \Drupal\Core\Entity\ContentEntityBase $entity */ - $entity = $target_entities[$identifier]; - if ($entity->hasTranslation($active_langcode)) { - $entity = $entity->getTranslation($active_langcode); + if ($target_entity->hasTranslation($active_langcode)) { + $target_entity = $target_entity->getTranslation($active_langcode); } - $item->entity = $entity; - - if (!$item->entity->access('view')) { - continue; + if ($target_entity->access('view')) { + $item->entity = $target_entity; } } - else { - // This is an "auto_create" item, just leave the entity in place. + + if (!$item->entity->access('view')) { + continue; } // Mark item as accessible.