Version 1
[yaffs-website] / web / modules / contrib / paragraphs / src / ParagraphViewBuilder.php
diff --git a/web/modules/contrib/paragraphs/src/ParagraphViewBuilder.php b/web/modules/contrib/paragraphs/src/ParagraphViewBuilder.php
new file mode 100644 (file)
index 0000000..a485c26
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\paragraphs;
+
+use Drupal\Core\Entity\Entity\EntityViewDisplay;
+use Drupal\Core\Entity\EntityViewBuilder;
+
+/**
+ * Render controller for paragraphs.
+ */
+class ParagraphViewBuilder extends EntityViewBuilder {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildMultiple(array $build_list) {
+    $build_list = parent::buildMultiple($build_list);
+
+    // Allow enabled behavior plugin to alter the rendering.
+    foreach ($build_list as $key => $value) {
+      $display = EntityViewDisplay::load('paragraph.' . $value['#paragraph']->bundle() . '.' . $value['#view_mode']) ?: EntityViewDisplay::load('paragraph.' . $value['#paragraph']->bundle() . '.default');
+      $paragraph_type = $value['#paragraph']->getParagraphType();
+      foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin_value) {
+        $plugin_value->view($build_list[$key], $value['#paragraph'], $display, $value['#view_mode']);
+      }
+    }
+    return $build_list;
+  }
+
+}