Skip to content
Snippets Groups Projects
Commit 79e45043 authored by catch's avatar catch
Browse files

Issue #3515774 by prudloff, smustgrave: Cache tags added by...

Issue #3515774 by prudloff, smustgrave: Cache tags added by hook_block_view_BASE_BLOCK_ID_alter are ignored on blocks that implement MainContentBlockPluginInterface or TitleBlockPluginInterface

(cherry picked from commit 26b7e60d)
parent 98cb8e27
No related branches found
No related tags found
9 merge requests!12686Draft: Issue #3535330: Assets paths in CSS no longer rewritten when aggregation is enabled,!12661Issue #3255804 by godotislate, longwave, berdir, alexpott, catch, andypost,...,!12660Issue #3255804 by godotislate, longwave, berdir, alexpott, catch, andypost,...,!12618Issue #3522970 by longwave, smustgrave: Remove unused BrowserTestBase::$originalContainer,!12473Issue #3521639 by mstrelan, smustgrave for 11.2,!12462Issue #3523109 by ghost of drupal past, donquixote, nicxvan, dww, larowlan,...,!12357Issue #3529639 by mradcliffe, smustgrave, solomon.yifru: replacing a depricated css,!8811Issue #3129179: Provide some way to rebuild the persistent bundle field map,!7916Remove taxonomy dependency on node module - 11.x
Pipeline #509105 passed with warnings
Pipeline: drupal

#509110

    ...@@ -67,7 +67,11 @@ public function viewMultiple(array $entities = [], $view_mode = 'full', $langcod ...@@ -67,7 +67,11 @@ public function viewMultiple(array $entities = [], $view_mode = 'full', $langcod
    if ($plugin instanceof MainContentBlockPluginInterface || $plugin instanceof TitleBlockPluginInterface) { if ($plugin instanceof MainContentBlockPluginInterface || $plugin instanceof TitleBlockPluginInterface) {
    // Immediately build a #pre_render-able block, since this block cannot // Immediately build a #pre_render-able block, since this block cannot
    // be built lazily. // be built lazily.
    $build[$entity_id] += static::buildPreRenderableBlock($entity, $this->moduleHandler()); $cacheableMetadata = CacheableMetadata::createFromRenderArray($build[$entity_id]);
    $preRenderableBlock = static::buildPreRenderableBlock($entity, $this->moduleHandler());
    $cacheableMetadata->addCacheableDependency(CacheableMetadata::createFromRenderArray($preRenderableBlock));
    $build[$entity_id] += $preRenderableBlock;
    $cacheableMetadata->applyTo($build[$entity_id]);
    } }
    else { else {
    // Assign a #lazy_builder callback, which will generate a #pre_render- // Assign a #lazy_builder callback, which will generate a #pre_render-
    ......
    ...@@ -36,6 +36,16 @@ public function blockViewTestCacheAlter(array &$build, BlockPluginInterface $blo ...@@ -36,6 +36,16 @@ public function blockViewTestCacheAlter(array &$build, BlockPluginInterface $blo
    } }
    } }
    /**
    * Implements hook_block_view_BASE_BLOCK_ID_alter().
    *
    * @see \Drupal\Tests\block\Kernel\BlockViewBuilderTest::testBlockViewBuilderCacheTitleBlock()
    */
    #[Hook('block_view_page_title_block_alter')]
    public function blockViewPageTitleBlockAlter(array &$build, BlockPluginInterface $block): void {
    $build['#cache']['tags'][] = 'custom_cache_tag';
    }
    /** /**
    * Implements hook_block_build_BASE_BLOCK_ID_alter(). * Implements hook_block_build_BASE_BLOCK_ID_alter().
    */ */
    ......
    ...@@ -163,6 +163,30 @@ public function testBlockViewBuilderCache(): void { ...@@ -163,6 +163,30 @@ public function testBlockViewBuilderCache(): void {
    $this->verifyRenderCacheHandling(); $this->verifyRenderCacheHandling();
    } }
    /**
    * Tests title block render cache handling.
    *
    * @see \Drupal\block_test\Hook\BlockTestHooks::blockViewPageTitleBlockAlter()
    */
    public function testBlockViewBuilderCacheTitleBlock(): void {
    // Create title block.
    $this->block = $this->controller->create([
    'id' => 'test_block_title',
    'theme' => 'stark',
    'plugin' => 'page_title_block',
    ]);
    $this->block->save();
    $entity = Block::load('test_block_title');
    $builder = \Drupal::entityTypeManager()->getViewBuilder('block');
    $output = $builder->view($entity, 'block');
    $this->assertSame(
    ['block_view', 'config:block.block.test_block_title', 'custom_cache_tag'],
    $output['#cache']['tags']
    );
    }
    /** /**
    * Verifies render cache handling of the block being tested. * Verifies render cache handling of the block being tested.
    * *
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment