diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index 7c9c5c3..086a826 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -368,10 +368,9 @@ public function resetCache(array $entities = NULL) { if (isset($entities)) { $tags = []; foreach ($entities as $entity) { - $tags = array_merge($tags, $entity->getCacheTags()); - $tags = array_merge($tags, $entity->getEntityType()->getListCacheTags()); + $tags = Cache::mergeTags($tags, $entity->getCacheTags()); + $tags = Cache::mergeTags($tags, $entity->getEntityType()->getListCacheTags()); } - $tags = Cache::mergeTags($tags) Cache::invalidateTags($tags); } else { diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 0990f17..6d5c7bd 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -48,15 +48,14 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la $derivative_id = $plugin->getDerivativeId(); $configuration = $plugin->getConfiguration(); - $cache_tags = array_merge( + $cache_tags = Cache::mergeTags( $this->getCacheTags(), // Block view builder cache tag. $entity->getCacheTags() // Block entity cache tag. ); - $cache_tags = array_merge( + $cache_tags = Cache::mergeTags( $cache_tags, $plugin->getCacheTags() // Block plugin cache tags. ); - $cache_tags = Cache::mergeTags($cache_tags); // Create the render array for the block as a whole. // @see template_preprocess_block(). diff --git a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php index 819ef90..c3a07c4 100644 --- a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php +++ b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php @@ -91,16 +91,14 @@ public function testBlock() { // @see \Drupal\block\BlockViewBuilder::viewMultiple() $expected_block_cache_keys = ['entity_view', 'block', $block->id()]; $expected_block_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme']; - $expected_block_cache_tags = array_merge(['block_view', 'rendered'], $block->getCacheTags()); - $expected_block_cache_tags = array_merge($expected_block_cache_tags, $block->getPlugin()->getCacheTags()); - $expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags); + $expected_block_cache_tags = Cache::mergeTags(['block_view', 'rendered'], $block->getCacheTags()); + $expected_block_cache_tags = Cache::mergeTags($expected_block_cache_tags, $block->getPlugin()->getCacheTags()); // Expected contexts and tags for the BlockContent entity. // @see \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults(). $expected_entity_cache_contexts = ['theme']; - $expected_entity_cache_tags = array_merge(['block_content_view'], $this->entity->getCacheTags()); - $expected_entity_cache_tags = array_merge($expected_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags); + $expected_entity_cache_tags = Cache::mergeTags(['block_content_view'], $this->entity->getCacheTags()); + $expected_entity_cache_tags = Cache::mergeTags($expected_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); // Verify that what was render cached matches the above expectations. $cid = $this->createCacheId($expected_block_cache_keys, $expected_block_cache_contexts); diff --git a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php index 7259dc9..f46ad04 100644 --- a/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php @@ -350,38 +350,36 @@ public function testReferencedEntity() { } // Generate the cache tags for the (non) referencing entities. - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $this->referencingEntity->getCacheTags(), \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags() ); - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $referencing_entity_cache_tags, // Includes the main entity's cache tags, since this entity references it. $this->entity->getCacheTags() ); - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $referencing_entity_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity) ); - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $referencing_entity_cache_tags, $view_cache_tag ); - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $referencing_entity_cache_tags, ['rendered'] ); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags); - $non_referencing_entity_cache_tags = array_merge( + $non_referencing_entity_cache_tags = Cache::mergeTags( $this->nonReferencingEntity->getCacheTags(), \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags() ); - $non_referencing_entity_cache_tags = array_merge( + $non_referencing_entity_cache_tags = Cache::mergeTags( $non_referencing_entity_cache_tags, ['rendered'] ); - $non_referencing_entity_cache_tags = Cache::mergeTags($non_referencing_entity_cache_tags); // Generate the cache tags for all two possible entity listing paths. // 1. list cache tag only (listing query has no match) @@ -391,27 +389,26 @@ public function testReferencedEntity() { $page_cache_tags ); - $nonempty_entity_listing_cache_tags = array_merge( + $nonempty_entity_listing_cache_tags = Cache::mergeTags( $this->entity->getEntityType()->getListCacheTags(), $this->entity->getCacheTags() ); - $nonempty_entity_listing_cache_tags = array_merge( + $nonempty_entity_listing_cache_tags = Cache::mergeTags( $nonempty_entity_listing_cache_tags, $this->getAdditionalCacheTagsForEntityListing($this->entity) ); - $nonempty_entity_listing_cache_tags = array_merge( + $nonempty_entity_listing_cache_tags = Cache::mergeTags( $nonempty_entity_listing_cache_tags, $page_cache_tags ); - $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags); + $this->pass("Test referencing entity.", 'Debug'); $this->verifyPageCache($referencing_entity_url, 'MISS'); // Verify a cache hit, but also the presence of the correct cache tags. $expectedTags = []; - $expectedTags = array_merge($referencing_entity_cache_tags, $page_cache_tags); - $expectedTags = array_merge($expectedTags, $page_cache_tags_referencing_entity); - $expectedTags = cache::mergeTags($expectedTags); + $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); + $expectedTags = Cache::mergeTags($expectedTags, $page_cache_tags_referencing_entity); $this->verifyPageCache($referencing_entity_url, 'HIT', $expectedTags); // Also verify the existence of an entity render cache entry. @@ -442,9 +439,8 @@ public function testReferencedEntity() { // Verify a cache hit, but also the presence of the correct cache tags. $expectedTags = []; - $expectedTags = array_merge($referencing_entity_cache_tags, $page_cache_tags); - $expectedTags = array_merge($expectedTags, $page_cache_tags_referencing_entity); - $expectedTags = Cache::mergeTags($expectedTags); + $expectedTags = Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags); + $expectedTags = Cache::mergeTags($expectedTags, $page_cache_tags_referencing_entity); $this->verifyPageCache($listing_url, 'HIT', $expectedTags); $this->pass("Test empty listing.", 'Debug'); @@ -664,25 +660,23 @@ public function testReferencedEntity() { $this->verifyPageCache($non_referencing_entity_url, 'HIT'); // Verify cache hits. - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $this->referencingEntity->getCacheTags(), \Drupal::entityManager()->getViewBuilder('entity_test')->getCacheTags() ); - $referencing_entity_cache_tags = array_merge( + $referencing_entity_cache_tags = Cache::mergeTags( $referencing_entity_cache_tags, ['rendered'] ); - $referencing_entity_cache_tags = Cache::mergeTags($referencing_entity_cache_tags); - $nonempty_entity_listing_cache_tags = array_merge( + $nonempty_entity_listing_cache_tags = Cache::mergeTags( $this->entity->getEntityType()->getListCacheTags(), $this->getAdditionalCacheTagsForEntityListing() ); - $nonempty_entity_listing_cache_tags = array_merge( + $nonempty_entity_listing_cache_tags = Cache::mergeTags( $nonempty_entity_listing_cache_tags, $page_cache_tags ); - $nonempty_entity_listing_cache_tags = Cache::mergeTags($nonempty_entity_listing_cache_tags); $this->verifyPageCache($referencing_entity_url, 'HIT', Cache::mergeTags($referencing_entity_cache_tags, $page_cache_tags)); $this->verifyPageCache($listing_url, 'HIT', $page_cache_tags); diff --git a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php index a410c49..abbcad3 100644 --- a/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php +++ b/core/modules/system/src/Tests/Entity/EntityWithUriCacheTagsTestBase.php @@ -56,10 +56,9 @@ public function testEntityUri() { if (count($additional_cache_contexts)) { $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts)); } - $expected_cache_tags = array_merge($cache_tag, $view_cache_tag); - $expected_cache_tags = array_merge($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $expected_cache_tags = array_merge($expected_cache_tags, array($render_cache_tag)); - $expected_cache_tags = Cache::mergeTags($expected_cache_tags); + $expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag); + $expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); + $expected_cache_tags = Cache::mergeTags($expected_cache_tags, array($render_cache_tag)); $this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid); } diff --git a/core/modules/views/src/Tests/RenderCacheIntegrationTest.php b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php index 4a7e907..b1235b1 100644 --- a/core/modules/views/src/Tests/RenderCacheIntegrationTest.php +++ b/core/modules/views/src/Tests/RenderCacheIntegrationTest.php @@ -124,12 +124,7 @@ protected function assertCacheTagsForFieldBasedView($do_assert_views_caches) { $this->pass('Test pager'); $this->pass('Page 1'); \Drupal::request()->query->set('page', 0); - $tags_page_1 = array_merge($base_tags, $entities[1]->getCacheTags()); - $tags_page_1 = array_merge($tags_page_1, $entities[2]->getCacheTags() - $tags_page_1 = array_mergemergeTags($tags_page_1, $entities[3]->getCacheTags() - $tags_page_1 = array_merge($tags_page_1, $entities[4]->getCacheTags() - $tags_page_1 = array_merge($tags_page_1, $entities[5]->getCacheTags()); - $tags_page_1 = Cache::mergeTags($tags_page_1); + $tags_page_1 = Cache::mergeTags($base_tags, $entities[1]->getCacheTags(), $entities[2]->getCacheTags(), $entities[3]->getCacheTags(), $entities[4]->getCacheTags(), $entities[5]->getCacheTags()); $this->assertViewsCacheTags($view, $tags_page_1, $do_assert_views_caches, $tags_page_1); $this->assertViewsCacheTagsFromStaticRenderArray($view, $tags_page_1, $do_assert_views_caches); $view->destroy(); @@ -259,9 +254,7 @@ protected function assertCacheTagsForEntityBasedView($do_assert_views_caches) { $entity->save(); $result_tags_with_entity = Cache::mergeTags($base_tags, $entities[0]->getCacheTags()); - $render_tags_with_entity = array_merge($base_render_tags, $entities[0]->getCacheTags()); - $render_tags_with_entity = array_merge($render_tags_with_entity, ['entity_test_view']); - $render_tags_with_entity = Cache::mergeTags($render_tags_with_entity); + $render_tags_with_entity = Cache::mergeTags($base_render_tags, $entities[0]->getCacheTags(), ['entity_test_view']); $this->assertViewsCacheTags($view, $result_tags_with_entity, $do_assert_views_caches, $render_tags_with_entity); $this->assertViewsCacheTagsFromStaticRenderArray($view, $render_tags_with_entity, $do_assert_views_caches); @@ -272,15 +265,9 @@ protected function assertCacheTagsForEntityBasedView($do_assert_views_caches) { $entity->save(); } - $new_entities_cache_tags = array_merge($entities[1]->getCacheTags(), $entities[2]->getCacheTags()); - $new_entities_cache_tags = array_merge($new_entities_cache_tags, $entities[3]->getCacheTags()); - $new_entities_cache_tags = array_merge($new_entities_cache_tags, $entities[4]->getCacheTags()); - $new_entities_cache_tags = array_merge($new_entities_cache_tags, $entities[5]->getCacheTags()); - $new_entities_cache_tags = Cache::mergeTags($new_entities_cache_tags); + $new_entities_cache_tags = Cache::mergeTags($entities[1]->getCacheTags(), $entities[2]->getCacheTags(), $entities[3]->getCacheTags(), $entities[4]->getCacheTags(), $entities[5]->getCacheTags()); $result_tags_page_1 = Cache::mergeTags($base_tags, $new_entities_cache_tags); - $render_tags_page_1 = array_merge($base_render_tags, $new_entities_cache_tags); - $render_tags_page_1 = array_merge($render_tags_page_1, ['entity_test_view']); - $render_tags_page_1 = Cache::mergeTags($render_tags_page_1); + $render_tags_page_1 = Cache::mergeTags($base_render_tags, $new_entities_cache_tags, ['entity_test_view']); $this->assertViewsCacheTags($view, $result_tags_page_1, $do_assert_views_caches, $render_tags_page_1); $this->assertViewsCacheTagsFromStaticRenderArray($view, $render_tags_page_1, $do_assert_views_caches); }