Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity_reference_revisions / src / Plugin / Field / FieldFormatter / EntityReferenceRevisionsFormatterBase.php
diff --git a/web/modules/contrib/entity_reference_revisions/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php b/web/modules/contrib/entity_reference_revisions/src/Plugin/Field/FieldFormatter/EntityReferenceRevisionsFormatterBase.php
new file mode 100644 (file)
index 0000000..e098f52
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter;
+
+use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
+
+/**
+ * Parent plugin for entity reference formatters.
+ */
+abstract class EntityReferenceRevisionsFormatterBase extends EntityReferenceFormatterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function prepareView(array $entities_items) {
+    // Entity revision loading currently has no static/persistent cache and no
+    // 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 ($item->entity) {
+          $item->_loaded = TRUE;
+        }
+      }
+    }
+  }
+
+}