You are here

public function SectionStorageBase::getContextsDuringPreview in Drupal 10

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

File

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

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