public function LayoutParagraphsFormatter::buildLayoutContainer in Layout Paragraphs 1.0.x
Builds the structure for a single layout paragraph item.
Also adds elements for the layout instance and regions. Regions will be populated with paragraphs further down the line, then rendered in the layout.
Parameters
\Drupal\paragraphs\ParagraphInterface $layout_entity: The layout paragraph to render.
array $entities: The array of remaining entities to process, adding to layout entity where applicable.
Return value
array Returns a build array.
Throws
\Drupal\Component\Plugin\Exception\PluginException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\TypedData\Exception\MissingDataException
1 call to LayoutParagraphsFormatter::buildLayoutContainer()
- LayoutParagraphsFormatter::buildLayoutTree in src/
Plugin/ Field/ FieldFormatter/ LayoutParagraphsFormatter.php - Builds the structure for the entire layout.
File
- src/
Plugin/ Field/ FieldFormatter/ LayoutParagraphsFormatter.php, line 171
Class
- LayoutParagraphsFormatter
- Layout Paragraphs field formatter.
Namespace
Drupal\layout_paragraphs\Plugin\Field\FieldFormatterCode
public function buildLayoutContainer(ParagraphInterface $layout_entity, array &$entities) {
/** @var Drupal\layout_paragraphs\Plugin\Field\FieldType\EntityReferenceLayoutRevisioned $referringItem */
$layout = $layout_entity
->getBehaviorSetting('layout_paragraphs', 'layout', '');
$config = $layout_entity
->getBehaviorSetting('layout_paragraphs', 'config', []);
$layout_uuid = $layout_entity
->uuid();
if (!$this->layoutPluginManager
->getDefinition($layout, FALSE)) {
$messenger = \Drupal::messenger();
$messenger
->addMessage($this
->t('Layout `%layout_id` is unknown.', [
'%layout_id' => $layout,
]), 'warning');
return [];
}
$layout_instance = $this->layoutPluginManager
->createInstance($layout, $config);
$build = $this
->buildEntityView($layout_entity);
$build['regions'] = [];
foreach ($entities as $index => $entity) {
$parent_uuid = $entity
->getBehaviorSetting('layout_paragraphs', 'parent_uuid', '');
$region = $entity
->getBehaviorSetting('layout_paragraphs', 'region', '');
if ($parent_uuid == $layout_uuid && !empty($region)) {
unset($entities[$index]);
if ($entity
->getBehaviorSetting('layout_paragraphs', 'layout', '')) {
$build['regions'][$region][$entity
->uuid()] = $this
->buildLayoutContainer($entity, $entities);
}
else {
$build['regions'][$region][$entity
->uuid()] = $this
->buildEntityView($entity);
}
}
}
$build['regions'] = [
'#weight' => 1000,
] + $layout_instance
->build($build['regions']);
return $build;
}