diff --git a/core/modules/layout_builder/layout_builder.post_update.php b/core/modules/layout_builder/layout_builder.post_update.php index d93113b7ab..0ee7390dd5 100644 --- a/core/modules/layout_builder/layout_builder.post_update.php +++ b/core/modules/layout_builder/layout_builder.post_update.php @@ -65,3 +65,10 @@ function layout_builder_post_update_add_extra_fields(&$sandbox = NULL) { function layout_builder_post_update_section_storage_context_definitions() { // Empty post-update hook. } + +/** + * Clear caches due to changes to annotation changes to the Overrides plugin. + */ +function layout_builder_post_update_overrides_view_mode_annotation() { + // Empty post-update hook. +} diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php index 702b667774..fa0c6c2f6d 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php @@ -9,6 +9,8 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Plugin\Context\Context; +use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; @@ -157,6 +159,9 @@ public function deriveContextsFromRoute($value, $definition, $name, array $defau 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. + $contexts['view_mode'] = new Context(new ContextDefinition('string'), 'full'); } return $contexts; } diff --git a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php index ece8511dfc..bea812a87c 100644 --- a/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Kernel/OverridesSectionStorageTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\layout_builder\Kernel; +use Drupal\Core\Plugin\Context\Context; +use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\EntityContext; use Drupal\entity_test\Entity\EntityTest; use Drupal\KernelTests\KernelTestBase; @@ -81,6 +83,7 @@ public function testAccess($expected, $operation, $is_enabled, array $section_da $entity->save(); $this->plugin->setContext('entity', EntityContext::fromEntity($entity)); + $this->plugin->setContext('view_mode', new Context(new ContextDefinition('string'), 'default')); $result = $this->plugin->access($operation); $this->assertSame($expected, $result); }