3 namespace Drupal\paragraphs;
5 use Drupal\Core\Entity\Entity\EntityViewDisplay;
6 use Drupal\Core\Entity\EntityViewBuilder;
7 use Drupal\Core\Render\Element;
10 * Render controller for paragraphs.
12 class ParagraphViewBuilder extends EntityViewBuilder {
17 public function buildMultiple(array $build_list) {
18 $build_list = parent::buildMultiple($build_list);
20 // Allow enabled behavior plugin to alter the rendering.
21 foreach (Element::children($build_list) as $key) {
22 $build = $build_list[$key];
23 $display = EntityViewDisplay::load('paragraph.' . $build['#paragraph']->bundle() . '.' . $build['#view_mode']) ?: EntityViewDisplay::load('paragraph.' . $build['#paragraph']->bundle() . '.default');
24 $paragraph_type = $build['#paragraph']->getParagraphType();
26 // In case we use paragraphs type with no fields the EntityViewDisplay
27 // might not be available yet.
29 $display = EntityViewDisplay::create([
30 'targetEntityType' => 'paragraph',
31 'bundle' => $build['#paragraph']->bundle(),
37 foreach ($paragraph_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin_value) {
38 $plugin_value->view($build_list[$key], $build['#paragraph'], $display, $build['#view_mode']);