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 = []; $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[] */ /* @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $id => $block) { foreach ($blocks as $id => $block) {
@ -537,8 +540,8 @@ class TwigExtension extends AbstractExtension {
if ($build) { if ($build) {
$build['#region'] = $region; $build['#region'] = $region;
$build['#theme_wrappers'] = ['region']; $build['#theme_wrappers'] = ['region'];
$cache_metadata->applyTo($build);
} }
$cache_metadata->applyTo($build);
return $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\Access\AccessResult;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
@ -371,6 +372,13 @@ class AccessTest extends KernelTestBase {
$view_builder->expects($this->any()) $view_builder->expects($this->any())
->method('view') ->method('view')
->willReturn($content); ->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 = $this->createMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any()) $entity_type_manager->expects($this->any())
@ -379,6 +387,9 @@ class AccessTest extends KernelTestBase {
$entity_type_manager->expects($this->any()) $entity_type_manager->expects($this->any())
->method('getViewBuilder') ->method('getViewBuilder')
->willReturn($view_builder); ->willReturn($view_builder);
$entity_type_manager->expects($this->any())
->method('getDefinition')
->willReturn($entity_type);
$this->container->set('entity_type.manager', $entity_type_manager); $this->container->set('entity_type.manager', $entity_type_manager);

Loading…
Cancel
Save