function LayoutBuilderEntityViewDisplay::buildSections

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildSections()
  2. 8.9.x core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildSections()
  3. 10 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildSections()

Builds the render array for the sections of a given entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity.

Return value

array The render array representing the sections of the entity.

1 call to LayoutBuilderEntityViewDisplay::buildSections()
LayoutBuilderEntityViewDisplay::buildMultiple in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Builds a renderable array for the components of a set of entities.

File

core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php, line 318

Class

LayoutBuilderEntityViewDisplay
Provides an entity view display entity that has a layout.

Namespace

Drupal\layout_builder\Entity

Code

protected function buildSections(FieldableEntityInterface $entity) {
    $contexts = $this->getContextsForEntity($entity);
    $label = new TranslatableMarkup('@entity being viewed', [
        '@entity' => $entity->getEntityType()
            ->getSingularLabel(),
    ]);
    $contexts['layout_builder.entity'] = EntityContext::fromEntity($entity, $label);
    $cacheability = new CacheableMetadata();
    $storage = $this->sectionStorageManager()
        ->findByContext($contexts, $cacheability);
    $build = [];
    if ($storage) {
        foreach ($storage->getSections() as $delta => $section) {
            $build[$delta] = $section->toRenderArray($contexts);
        }
    }
    // The render array is built based on decisions made by SectionStorage
    // plugins and therefore it needs to depend on the accumulated
    // cacheability of those decisions.
    $cacheability->applyTo($build);
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.