You are here

public function OverridesSectionStorage::deriveContextsFromRoute in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()
  2. 9 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()

File

core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php, line 166

Class

OverridesSectionStorage
Defines the 'overrides' section storage type.

Namespace

Drupal\layout_builder\Plugin\SectionStorage

Code

public function deriveContextsFromRoute($value, $definition, $name, array $defaults) {
  $contexts = [];
  if ($entity = $this
    ->extractEntityFromRoute($value, $defaults)) {
    $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;
}