core/modules/block/src/BlockViewBuilder.php | 2 +- core/modules/block/src/Tests/BlockViewBuilderTest.php | 13 ++++++++----- .../block/tests/modules/block_test/block_test.module | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 9d1fa80..c3d6147 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -75,7 +75,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $this->getCacheTag(), // Block view builder cache tag. $entity->getCacheTag(), // Block entity cache tag. $entity->getListCacheTags(), // Block entity list cache tags. - $plugin->getCacheTags(), // Block plugin cache tags. + $plugin->getCacheTags() // Block plugin cache tags. ); if ($plugin->isCacheable()) { diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php index c9b1583..a115c6d 100644 --- a/core/modules/block/src/Tests/BlockViewBuilderTest.php +++ b/core/modules/block/src/Tests/BlockViewBuilderTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\UrlCacheContext; use Drupal\simpletest\DrupalUnitTestBase; use Symfony\Component\HttpFoundation\Request; @@ -236,22 +237,24 @@ public function testBlockViewBuilderAlter() { $this->assertIdentical(drupal_render($build), ''); $cache_entry = $this->container->get('cache.render')->get($cid); $this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.'); - $expected_flattened_tags = array('block_view:1', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', 'rendered:1'); - $this->assertIdentical($cache_entry->tags, $expected_flattened_tags, 'The block render element has been cached with the expected cache tags.'); + $expected_tags = array('block_view', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', 'rendered'); + sort($expected_tags); + $this->assertIdentical($cache_entry->tags, $expected_tags, 'The block render element has been cached with the expected cache tags.'); $this->container->get('cache.render')->delete($cid); // Advanced: cached block, but an alter hook adds an additional cache tag. $alter_add_tag = $this->randomMachineName(); \Drupal::state()->set('block_test_view_alter_cache_tag', $alter_add_tag); - $expected_tags = NestedArray::mergeDeep($default_tags, array($alter_add_tag => TRUE)); + $expected_tags = Cache::mergeTags($default_tags, array($alter_add_tag)); $build = $this->getBlockRenderArray(); $this->assertIdentical($expected_tags, $build['#cache']['tags'], 'An altered cacheable block has the expected cache tags.'); $cid = drupal_render_cid_create(array('#cache' => array('keys' => $expected_keys))); $this->assertIdentical(drupal_render($build), ''); $cache_entry = $this->container->get('cache.render')->get($cid); $this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.'); - $expected_flattened_tags = array('block_view:1', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', $alter_add_tag . ':1', 'rendered:1'); - $this->assertIdentical($cache_entry->tags, $expected_flattened_tags, 'The block render element has been cached with the expected cache tags.'); + $expected_tags = array('block_view', 'block:test_block', 'theme:stark', 'block_plugin:test_cache', $alter_add_tag, 'rendered'); + sort($expected_tags); + $this->assertIdentical($cache_entry->tags, $expected_tags, 'The block render element has been cached with the expected cache tags.'); $this->container->get('cache.render')->delete($cid); // Advanced: cached block, but an alter hook adds a #pre_render callback to diff --git a/core/modules/block/tests/modules/block_test/block_test.module b/core/modules/block/tests/modules/block_test/block_test.module index d4bf97f..19e65ad 100644 --- a/core/modules/block/tests/modules/block_test/block_test.module +++ b/core/modules/block/tests/modules/block_test/block_test.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Block\BlockPluginInterface; +use Drupal\Core\Cache\Cache; /** * Implements hook_block_alter(). @@ -27,7 +28,7 @@ function block_test_block_view_test_cache_alter(array &$build, BlockPluginInterf $build['#cache']['keys'][] = \Drupal::state()->get('block_test_view_alter_cache_key'); } if (\Drupal::state()->get('block_test_view_alter_cache_tag') !== NULL) { - $build['#cache']['tags'][\Drupal::state()->get('block_test_view_alter_cache_tag')] = TRUE; + $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], [\Drupal::state()->get('block_test_view_alter_cache_tag')]); } if (\Drupal::state()->get('block_test_view_alter_append_pre_render_prefix') !== NULL) { $build['#pre_render'][] = 'block_test_pre_render_alter_content';