Browse Source

Clean-up BlockViewBuilder.php

merge-requests/2/head
Chi 5 years ago
parent
commit
3f3633dcfe
  1. 9
      src/View/BlockViewBuilder.php
  2. 16
      tests/src/Kernel/BlockViewBuilderTest.php

9
src/View/BlockViewBuilder.php

@ -151,9 +151,12 @@ class BlockViewBuilder {
->applyTo($build); ->applyTo($build);
if (!isset($build['#cache']['keys'])) { if (!isset($build['#cache']['keys'])) {
$configuration['_wrapper'] = $wrapper; $build['#cache']['keys'] = [
$configuration_hash = hash('sha256', serialize($configuration)); 'twig_tweak_block',
$build['#cache']['keys'] = ['twig_tweak_block', $id, $configuration_hash]; $id,
'[configuration]=' . hash('sha256', serialize($configuration)),
'[wrapper]=' . (int) $wrapper,
];
} }
return $build; return $build;

16
tests/src/Kernel/BlockViewBuilderTest.php

@ -65,7 +65,8 @@ final class BlockViewBuilderTest extends KernelTestBase {
'keys' => [ 'keys' => [
'twig_tweak_block', 'twig_tweak_block',
'twig_tweak_test_foo', 'twig_tweak_test_foo',
'9ef25a303eb97a01011ea20c50e731590c000f8bc6196241020fc118cce68180', '[configuration]=04c46ea912d2866a3a36c67326da1ef38f1c93cc822d6c45e1639f3decdebbdc',
'[wrapper]=1',
], ],
], ],
]; ];
@ -77,7 +78,12 @@ final class BlockViewBuilderTest extends KernelTestBase {
$expected_build['content']['#markup'] = 'Bar'; $expected_build['content']['#markup'] = 'Bar';
$expected_build['#configuration']['label'] = 'Example'; $expected_build['#configuration']['label'] = 'Example';
$expected_build['#configuration']['content'] = 'Bar'; $expected_build['#configuration']['content'] = 'Bar';
$expected_build['#cache']['keys'][2] = '96b740819b50d416148484351f52de1c894b63cf59af255b502c9399c73b8557'; $expected_build['#cache']['keys'] = [
'twig_tweak_block',
'twig_tweak_test_foo',
'[configuration]=373b0811b355fa153ac8934c897a021697ff6e848f00b85e711d36212b77a958',
'[wrapper]=1',
];
self::assertSame($expected_build, $build); self::assertSame($expected_build, $build);
self::assertSame('<div><h2>Example</h2>Bar</div>', $this->renderPlain($build)); self::assertSame('<div><h2>Example</h2>Bar</div>', $this->renderPlain($build));
@ -98,7 +104,8 @@ final class BlockViewBuilderTest extends KernelTestBase {
'keys' => [ 'keys' => [
'twig_tweak_block', 'twig_tweak_block',
'twig_tweak_test_foo', 'twig_tweak_test_foo',
'82b254ef229c95f336386ee50454e0cc56705e97c1991d68fe9afdb1fb401f3a', '[configuration]=04c46ea912d2866a3a36c67326da1ef38f1c93cc822d6c45e1639f3decdebbdc',
'[wrapper]=0',
], ],
], ],
]; ];
@ -116,7 +123,8 @@ final class BlockViewBuilderTest extends KernelTestBase {
'keys' => [ 'keys' => [
'twig_tweak_block', 'twig_tweak_block',
'twig_tweak_test_foo', 'twig_tweak_test_foo',
'9ef25a303eb97a01011ea20c50e731590c000f8bc6196241020fc118cce68180', '[configuration]=04c46ea912d2866a3a36c67326da1ef38f1c93cc822d6c45e1639f3decdebbdc',
'[wrapper]=1',
], ],
], ],
]; ];

Loading…
Cancel
Save