diff --git a/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php b/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php index fa7bcbd..dd497ad 100644 --- a/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php +++ b/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php @@ -14,19 +14,14 @@ abstract class EntityReferenceRevisionsFormatterBase extends EntityReferenceForm */ public function prepareView(array $entities_items) { // Entity revision loading currently has no static/persistent cache and no - // multiload. Simulate that the entities have been loaded by setting the - // special _loaded property to TRUE but do not actually load them, they - // will be loaded automatically if that didn't happen yet. + // multiload. As entity reference checks _loaded, while we don't want to + // indicate a loaded entity, when there is none, as it could cause errors, + // we actually load the entity and set the flag. foreach ($entities_items as $items) { foreach ($items as $item) { - if ($this->needsEntityLoad($item)) { - $target_type = $this->getFieldSetting('target_type'); - $entity = \Drupal::entityTypeManager()->getStorage($target_type)->loadRevision($item->target_revision_id); - if ($entity) { - $item->entity = $entity; - $item->_loaded = TRUE; - } + if ($this->needsEntityLoad($item) && $item->entity) { + $item->_loaded = TRUE; } } } diff --git a/tests/modules/entity_composite_relationship_test/Entity_composite_relationship_test.permissions.yml b/tests/modules/entity_composite_relationship_test/entity_composite_relationship_test.permissions.yml similarity index 100% rename from tests/modules/entity_composite_relationship_test/Entity_composite_relationship_test.permissions.yml rename to tests/modules/entity_composite_relationship_test/entity_composite_relationship_test.permissions.yml