You are here

public function LayoutBuilderEntityViewDisplay::buildMultiple in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::buildMultiple()

Builds a renderable array for the components of a set of entities.

This only includes the components handled by the Display object, but excludes 'extra fields', that are typically rendered through specific, ad-hoc code in EntityViewBuilderInterface::buildComponents() or in hook_entity_view() implementations.

hook_entity_display_build_alter() is invoked on each entity, allowing 3rd party code to alter the render array.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface[] $entities: The entities being displayed.

Return value

array A renderable array for the entities, indexed by the same keys as the $entities array parameter.

Overrides EntityViewDisplay::buildMultiple

See also

hook_entity_display_build_alter()

File

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

Class

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

Namespace

Drupal\layout_builder\Entity

Code

public function buildMultiple(array $entities) {
  $build_list = parent::buildMultiple($entities);

  // Layout Builder can not be enabled for the '_custom' view mode that is
  // used for on-the-fly rendering of fields in isolation from the entity.
  if ($this
    ->isCustomMode()) {
    return $build_list;
  }
  foreach ($entities as $id => $entity) {
    $build_list[$id]['_layout_builder'] = $this
      ->buildSections($entity);

    // If there are any sections, remove all fields with configurable display
    // from the existing build. These fields are replicated within sections as
    // field blocks by ::setComponent().
    if (!Element::isEmpty($build_list[$id]['_layout_builder'])) {
      foreach ($build_list[$id] as $name => $build_part) {
        $field_definition = $this
          ->getFieldDefinition($name);
        if ($field_definition && $field_definition
          ->isDisplayConfigurable($this->displayContext)) {
          unset($build_list[$id][$name]);
        }
      }
    }
  }
  return $build_list;
}