You are here

public function SectionStorageBase::getContextsDuringPreview in Drupal 8

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. 10 core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php \Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase::getContextsDuringPreview()

Gets contexts for use during preview.

When not in preview, ::getContexts() will be used.

Return value

\Drupal\Core\Plugin\Context\ContextInterface[] The plugin contexts suitable for previewing.

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 113

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