core/modules/layout_builder/layout_builder.module | 2 +- .../layout_builder/layout_builder.services.yml | 2 +- .../src/Cache/LayoutBuilderUiCacheContext.php | 32 ++-------------------- .../EventSubscriber/BlockComponentRenderArray.php | 7 ++--- .../FunctionalJavascript/ContextualLinksTest.php | 6 ++-- 5 files changed, 11 insertions(+), 38 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 40e86c843a..c16bd380e1 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -165,7 +165,7 @@ function layout_builder_entity_build_defaults_alter(array &$build, EntityInterfa // Contextual links are removed for entities viewed in Layout Builder's UI. // The route.layout_builder_ui cache context accounts for this difference. // @see layout_builder_entity_view_alter() - // @see Drupal\layout_builder\Cache\LayoutBuilderUiCacheContext + // @see \Drupal\layout_builder\Cache\LayoutBuilderUiCacheContext $build['#cache']['contexts'][] = 'route.layout_builder_ui'; } diff --git a/core/modules/layout_builder/layout_builder.services.yml b/core/modules/layout_builder/layout_builder.services.yml index 7ad864599f..bc022bfdb2 100644 --- a/core/modules/layout_builder/layout_builder.services.yml +++ b/core/modules/layout_builder/layout_builder.services.yml @@ -33,7 +33,7 @@ services: class: Drupal\layout_builder\Cache\LayoutBuilderUiCacheContext arguments: ['@current_route_match'] tags: - - { name: cache.context} + - { name: cache.context } layout_builder.sample_entity_generator: class: Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator arguments: ['@tempstore.shared', '@entity_type.manager'] diff --git a/core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php b/core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php index 1d9e74d555..ee6680a278 100644 --- a/core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php +++ b/core/modules/layout_builder/src/Cache/LayoutBuilderUiCacheContext.php @@ -2,39 +2,20 @@ namespace Drupal\layout_builder\Cache; -use Drupal\Core\Cache\CacheableMetadata; -use Drupal\Core\Cache\Context\CacheContextInterface; -use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Cache\Context\RouteCacheContext; /** * Determines if an entity is being viewed in the Layout Builder UI. * * Cache context ID: 'route.layout_builder_ui'. */ -class LayoutBuilderUiCacheContext implements CacheContextInterface { - - /** - * The current route match. - * - * @var \Drupal\Core\Routing\RouteMatchInterface - */ - protected $routeMatch; - - /** - * LayoutBuilderCacheContext constructor. - * - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The current route match. - */ - public function __construct(RouteMatchInterface $route_match) { - $this->routeMatch = $route_match; - } +class LayoutBuilderUiCacheContext extends RouteCacheContext { /** * {@inheritdoc} */ public static function getLabel() { - return t('Layout Builder UI'); + return t('Is Layout Builder UI route'); } /** @@ -44,11 +25,4 @@ public function getContext() { return strpos($this->routeMatch->getRouteName(), 'layout_builder.') === 0 ? 1 : 0; } - /** - * {@inheritdoc} - */ - public function getCacheableMetadata($parameter = NULL) { - return new CacheableMetadata(); - } - } diff --git a/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php b/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php index d3fb283d75..b48a2ec839 100644 --- a/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php +++ b/core/modules/layout_builder/src/EventSubscriber/BlockComponentRenderArray.php @@ -91,10 +91,9 @@ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) { if ($access->isAllowed()) { $event->addCacheableDependency($block); - // If the block is a Views Block in the Layout Builder UI, its - // contextual links placeholders must not get rendered. Doing this - // requires setting showAdminLinks to false before the View Block is - // built. + // If the block is a Views Block in the Layout Builder UI, its contextual + // links placeholders must not get rendered. Doing this requires setting + // showAdminLinks to false before the View Block is built. if ($block instanceof ViewsBlock && $event->inPreview()) { $block->getViewExecutable()->setShowAdminLinks(FALSE); } diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php index 71e05a52ff..0361f49bf6 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -61,7 +61,7 @@ protected function setUp() { } /** - * Tests the contextual links inside Layout Builder are removed. + * Tests that the contextual links inside Layout Builder are removed. */ public function testContextualLinks() { $page = $this->getSession()->getPage(); @@ -120,7 +120,7 @@ protected function addBlock($block_name) { } /** - * Assert the contextual links are correct in Layout Builder UI. + * Asserts the contextual links are correct in Layout Builder UI. */ protected function assertCorrectContextualLinksInUi() { $assert_session = $this->assertSession(); @@ -136,7 +136,7 @@ protected function assertCorrectContextualLinksInUi() { } /** - * Assert the contextual links are correct on the canonical entity route. + * Asserts the contextual links are correct on the canonical entity route. */ protected function assertCorrectContextualLinksInNode() { $assert_session = $this->assertSession();