function SectionStorageBase::getContextsDuringPreview

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase::getContextsDuringPreview()
  2. 8.9.x core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase::getContextsDuringPreview()
  3. 10 core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase::getContextsDuringPreview()

Overrides SectionStorageInterface::getContextsDuringPreview

2 calls to SectionStorageBase::getContextsDuringPreview()
DefaultsSectionStorage::getContextsDuringPreview in core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php
Gets contexts for use during preview.
OverridesSectionStorage::getContextsDuringPreview in core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php
Gets contexts for use during preview.
2 methods override SectionStorageBase::getContextsDuringPreview()
DefaultsSectionStorage::getContextsDuringPreview in core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php
Gets contexts for use during preview.
OverridesSectionStorage::getContextsDuringPreview in core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php
Gets contexts for use during preview.

File

core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php, line 94

Class

SectionStorageBase
Provides a base class for Section Storage types.

Namespace

Drupal\layout_builder\Plugin\SectionStorage

Code

public function getContextsDuringPreview() {
    $contexts = $this->getContexts();
    // view_mode is a required context, but SectionStorage plugins are not
    // required to return it (for example, the layout_library plugin provided
    // in the Layout Library module. In these instances, explicitly create a
    // view_mode context with the value "default".
    if (!isset($contexts['view_mode']) || $contexts['view_mode']->validate()
        ->count() || !$contexts['view_mode']->getContextValue()) {
        $contexts['view_mode'] = new Context(new ContextDefinition('string'), 'default');
    }
    return $contexts;
}

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