Skip to content
Snippets Groups Projects
Unverified Commit 8e37bfb0 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3088077 by Sam152, bkosborne, rensingh99, tim.plunkett: Layout builder...

Issue #3088077 by Sam152, bkosborne, rensingh99, tim.plunkett: Layout builder does not correctly bubble up cache metadata for empty blocks
parent f8127f8f
No related branches found
No related tags found
6 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
use Drupal\block_content\Access\RefinableDependentAccessInterface; use Drupal\block_content\Access\RefinableDependentAccessInterface;
use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockPluginInterface; use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Render\PreviewFallbackInterface; use Drupal\Core\Render\PreviewFallbackInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
...@@ -102,6 +103,12 @@ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) { ...@@ -102,6 +103,12 @@ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
} }
$content = $block->build(); $content = $block->build();
// We don't output the block render data if there are no render elements
// found, but we want to capture the cache metadata from the block
// regardless.
$event->addCacheableDependency(CacheableMetadata::createFromRenderArray($content));
$is_content_empty = Element::isEmpty($content); $is_content_empty = Element::isEmpty($content);
$is_placeholder_ready = $event->inPreview() && $block instanceof PreviewFallbackInterface; $is_placeholder_ready = $event->inPreview() && $block instanceof PreviewFallbackInterface;
// If the content is empty and no placeholder is available, return. // If the content is empty and no placeholder is available, return.
......
...@@ -99,7 +99,10 @@ public function testOnBuildRender($refinable_dependent_access) { ...@@ -99,7 +99,10 @@ public function testOnBuildRender($refinable_dependent_access) {
$placeholder_label = 'Placeholder Label'; $placeholder_label = 'Placeholder Label';
$block->getPreviewFallbackString()->willReturn($placeholder_label); $block->getPreviewFallbackString()->willReturn($placeholder_label);
$block_content = ['#markup' => 'The block content.']; $block_content = [
'#markup' => 'The block content.',
'#cache' => ['tags' => ['build-tag']],
];
$block->build()->willReturn($block_content); $block->build()->willReturn($block_content);
$this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal()); $this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal());
...@@ -122,7 +125,10 @@ public function testOnBuildRender($refinable_dependent_access) { ...@@ -122,7 +125,10 @@ public function testOnBuildRender($refinable_dependent_access) {
$expected_cache = $expected_build + [ $expected_cache = $expected_build + [
'#cache' => [ '#cache' => [
'contexts' => [], 'contexts' => [],
'tags' => ['test'], 'tags' => [
'build-tag',
'test',
],
'max-age' => -1, 'max-age' => -1,
], ],
]; ];
...@@ -410,7 +416,9 @@ public function testOnBuildRenderEmptyBuild() { ...@@ -410,7 +416,9 @@ public function testOnBuildRenderEmptyBuild() {
$block->getBaseId()->willReturn('block_plugin_id'); $block->getBaseId()->willReturn('block_plugin_id');
$block->getDerivativeId()->willReturn(NULL); $block->getDerivativeId()->willReturn(NULL);
$block->build()->willReturn([]); $block->build()->willReturn([
'#cache' => ['tags' => ['build-tag']],
]);
$this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal()); $this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal());
$component = new SectionComponent('some-uuid', 'some-region', ['id' => 'some_block_id']); $component = new SectionComponent('some-uuid', 'some-region', ['id' => 'some_block_id']);
...@@ -423,7 +431,10 @@ public function testOnBuildRenderEmptyBuild() { ...@@ -423,7 +431,10 @@ public function testOnBuildRenderEmptyBuild() {
$expected_cache = $expected_build + [ $expected_cache = $expected_build + [
'#cache' => [ '#cache' => [
'contexts' => [], 'contexts' => [],
'tags' => ['test'], 'tags' => [
'build-tag',
'test',
],
'max-age' => -1, 'max-age' => -1,
], ],
]; ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment