function OverridesSectionStorage::deriveContextsFromRoute

Same name in other branches
  1. 9 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()
  2. 10 core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()
  3. 11.x core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::deriveContextsFromRoute()

Overrides SectionStorageInterface::deriveContextsFromRoute

File

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

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

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