function LayoutEntityHelperTrait::getSectionStorageContextsForEntity

Gets the section storage contexts for an entity.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity with the overridden layout.

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] The section storage contexts.

2 calls to LayoutEntityHelperTrait::getSectionStorageContextsForEntity()
LayoutEntityHelperTrait::getOverridesSectionStorageForEntity in core/modules/layout_builder/src/LayoutEntityHelperTrait.php
Gets the overrides section storage for an entity.
OverridesSectionStorage::deriveContextsFromRoute in core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php
Derives the available plugin contexts from route values.

File

core/modules/layout_builder/src/LayoutEntityHelperTrait.php, line 181

Class

LayoutEntityHelperTrait
Methods to help with entities using the layout builder.

Namespace

Drupal\layout_builder

Code

public function getSectionStorageContextsForEntity(FieldableEntityInterface $entity) : array {
  $contexts = [];
  $contexts['entity'] = EntityContext::fromEntity($entity);
  // @todo Expand to work for all view modes in
  //   https://www.drupal.org/node/2907413.
  $view_mode = 'full';
  // Retrieve the actual view mode from the returned view display as the
  // requested view mode may not exist and a fallback will be used.
  $view_mode = LayoutBuilderEntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getMode();
  $contexts['view_mode'] = new Context(new ContextDefinition('string'), $view_mode);
  return $contexts;
}

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