Browse Source

Issue #3173946 by Charlie ChX Negyesi, larowlan: drupal_region() overcaches empty

merge-requests/4/head
CharlieChXNegyesi 4 years ago committed by Chi
parent
commit
05c880e09e
  1. 7
      src/TwigExtension.php
  2. 11
      tests/src/Kernel/AccessTest.php

7
src/TwigExtension.php

@ -516,7 +516,10 @@ class TwigExtension extends AbstractExtension {
$build = [];
$cache_metadata = new CacheableMetadata();
$entity_type = $entity_type_manager->getDefinition('block');
$cache_metadata = (new CacheableMetadata())
->addCacheTags($entity_type->getListCacheTags())
->addCacheContexts($entity_type->getListCacheContexts());
/* @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $id => $block) {
@ -537,8 +540,8 @@ class TwigExtension extends AbstractExtension {
if ($build) {
$build['#region'] = $region;
$build['#theme_wrappers'] = ['region'];
$cache_metadata->applyTo($build);
}
$cache_metadata->applyTo($build);
return $build;
}

11
tests/src/Kernel/AccessTest.php

@ -7,6 +7,7 @@ use Drupal\block\Entity\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\file\Entity\File;
@ -371,6 +372,13 @@ class AccessTest extends KernelTestBase {
$view_builder->expects($this->any())
->method('view')
->willReturn($content);
$entity_type = $this->createMock(EntityTypeInterface::class);
$entity_type->expects($this->any())
->method('getListCacheTags')
->willReturn([]);
$entity_type->expects($this->any())
->method('getListCacheContexts')
->willReturn([]);
$entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any())
@ -379,6 +387,9 @@ class AccessTest extends KernelTestBase {
$entity_type_manager->expects($this->any())
->method('getViewBuilder')
->willReturn($view_builder);
$entity_type_manager->expects($this->any())
->method('getDefinition')
->willReturn($entity_type);
$this->container->set('entity_type.manager', $entity_type_manager);

Loading…
Cancel
Save