diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php index cde6f497c5..eb3e12ef9b 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php @@ -39,7 +39,7 @@ * "entity" = @ContextDefinition("entity", constraints = { * "EntityHasField" = \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::FIELD_NAME, * }), - * "view_mode" = @ContextDefinition("string"), + * "view_mode" = @ContextDefinition("string", default_value = "default"), * } * ) * diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php index 3937ea5bcf..0f8543336f 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/SectionStorageBase.php @@ -116,8 +116,8 @@ public function getContextsDuringPreview() { // 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_modecontext with the value "default". - if (!isset($contexts['view_mode']) || !$contexts['view_mode']->getContextValue()) { + // 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;