Browse Source

Code clean-up

merge-requests/14/head
Chi 3 years ago
parent
commit
3b17ed3500
  1. 2
      src/TwigTweakExtension.php
  2. 4
      src/View/BlockViewBuilder.php
  3. 4
      src/View/EntityFormViewBuilder.php
  4. 4
      src/View/EntityViewBuilder.php
  5. 4
      src/View/FieldViewBuilder.php
  6. 3
      src/View/ImageViewBuilder.php
  7. 2
      src/View/RegionViewBuilder.php
  8. 22
      tests/src/Kernel/ImageViewBuilderTest.php

2
src/TwigTweakExtension.php

@ -547,7 +547,7 @@ class TwigTweakExtension extends AbstractExtension {
/** @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter $parent */ /** @var \Drupal\Core\Entity\Plugin\DataType\EntityAdapter $parent */
if ($parent = $object->getParent()) { if ($parent = $object->getParent()) {
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($parent->getEntity())) ->addCacheableDependency($parent->getEntity())
->applyTo($build); ->applyTo($build);
} }
} }

4
src/View/BlockViewBuilder.php

@ -162,8 +162,8 @@ class BlockViewBuilder {
} }
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($access)) ->addCacheableDependency($access)
->merge(CacheableMetadata::createFromObject($block_plugin)) ->addCacheableDependency($block_plugin)
->applyTo($build); ->applyTo($build);
if (!isset($build['#cache']['keys'])) { if (!isset($build['#cache']['keys'])) {

4
src/View/EntityFormViewBuilder.php

@ -50,8 +50,8 @@ class EntityFormViewBuilder {
} }
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($entity)) ->addCacheableDependency($access)
->merge(CacheableMetadata::createFromObject($access)) ->addCacheableDependency($entity)
->applyTo($build); ->applyTo($build);
return $build; return $build;

4
src/View/EntityViewBuilder.php

@ -38,8 +38,8 @@ class EntityViewBuilder {
->view($entity, $view_mode, $langcode); ->view($entity, $view_mode, $langcode);
} }
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($entity)) ->addCacheableDependency($access)
->merge(CacheableMetadata::createFromObject($access)) ->addCacheableDependency($entity)
->applyTo($build); ->applyTo($build);
return $build; return $build;
} }

4
src/View/FieldViewBuilder.php

@ -64,8 +64,8 @@ class FieldViewBuilder {
} }
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($access)) ->addCacheableDependency($access)
->merge(CacheableMetadata::createFromObject($entity)) ->addCacheableDependency($entity)
->applyTo($build); ->applyTo($build);
return $build; return $build;

3
src/View/ImageViewBuilder.php

@ -52,7 +52,8 @@ class ImageViewBuilder {
} }
CacheableMetadata::createFromRenderArray($build) CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromObject($access)) ->addCacheableDependency($access)
->addCacheableDependency($file)
->applyTo($build); ->applyTo($build);
return $build; return $build;

2
src/View/RegionViewBuilder.php

@ -89,7 +89,7 @@ class RegionViewBuilder {
/** @var \Drupal\block\BlockInterface[] $blocks */ /** @var \Drupal\block\BlockInterface[] $blocks */
foreach ($blocks as $id => $block) { foreach ($blocks as $id => $block) {
$access = $block->access('view', NULL, TRUE); $access = $block->access('view', NULL, TRUE);
$cache_metadata = $cache_metadata->merge(CacheableMetadata::createFromObject($access)); $cache_metadata = $cache_metadata->addCacheableDependency($access);
if ($access->isAllowed()) { if ($access->isAllowed()) {
$block_plugin = $block->getPlugin(); $block_plugin = $block->getPlugin();
if ($block_plugin instanceof TitleBlockPluginInterface) { if ($block_plugin instanceof TitleBlockPluginInterface) {

22
tests/src/Kernel/ImageViewBuilderTest.php

@ -76,7 +76,10 @@ final class ImageViewBuilderTest extends KernelTestBase {
'user', 'user',
'user.permissions', 'user.permissions',
], ],
'tags' => ['tag_for_public://ocean.jpg'], 'tags' => [
'file:1',
'tag_for_public://ocean.jpg',
],
'max-age' => 70, 'max-age' => 70,
], ],
]; ];
@ -95,7 +98,10 @@ final class ImageViewBuilderTest extends KernelTestBase {
'user', 'user',
'user.permissions', 'user.permissions',
], ],
'tags' => ['tag_for_public://ocean.jpg'], 'tags' => [
'file:1',
'tag_for_public://ocean.jpg',
],
'max-age' => 70, 'max-age' => 70,
], ],
]; ];
@ -114,7 +120,10 @@ final class ImageViewBuilderTest extends KernelTestBase {
'user', 'user',
'user.permissions', 'user.permissions',
], ],
'tags' => ['tag_for_public://ocean.jpg'], 'tags' => [
'file:1',
'tag_for_public://ocean.jpg',
],
'max-age' => 70, 'max-age' => 70,
], ],
]; ];
@ -126,7 +135,10 @@ final class ImageViewBuilderTest extends KernelTestBase {
$expected_build = [ $expected_build = [
'#cache' => [ '#cache' => [
'contexts' => ['user'], 'contexts' => ['user'],
'tags' => ['tag_for_private://sea.jpg'], 'tags' => [
'file:2',
'tag_for_private://sea.jpg',
],
'max-age' => 70, 'max-age' => 70,
], ],
]; ];
@ -141,7 +153,7 @@ final class ImageViewBuilderTest extends KernelTestBase {
'#theme' => 'image', '#theme' => 'image',
'#cache' => [ '#cache' => [
'contexts' => [], 'contexts' => [],
'tags' => [], 'tags' => ['file:2'],
'max-age' => Cache::PERMANENT, 'max-age' => Cache::PERMANENT,
], ],
]; ];

Loading…
Cancel
Save