You are here

protected function LayoutBuilderEntityViewDisplay::getContextsForEntity in Drupal 10

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

Gets the available contexts for a given entity.

Parameters

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

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] An array of context objects for a given entity.

1 call to LayoutBuilderEntityViewDisplay::getContextsForEntity()
LayoutBuilderEntityViewDisplay::buildSections in core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
Builds the render array for the sections of a given entity.

File

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

Class

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

Namespace

Drupal\layout_builder\Entity

Code

protected function getContextsForEntity(FieldableEntityInterface $entity) {
  $available_context_ids = array_keys($this
    ->contextRepository()
    ->getAvailableContexts());
  return [
    'view_mode' => new Context(ContextDefinition::create('string'), $this
      ->getMode()),
    'entity' => EntityContext::fromEntity($entity),
    'display' => EntityContext::fromEntity($this),
  ] + $this
    ->contextRepository()
    ->getRuntimeContexts($available_context_ids);
}