You are here

protected function LayoutBuilderEntityViewDisplay::buildSections in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildSections()
  2. 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 303

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);

  // @todo Remove in https://www.drupal.org/project/drupal/issues/3018782.
  $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;
}