diff --git a/src/View/BlockViewBuilder.php b/src/View/BlockViewBuilder.php index 379903d..957b396 100644 --- a/src/View/BlockViewBuilder.php +++ b/src/View/BlockViewBuilder.php @@ -151,9 +151,12 @@ class BlockViewBuilder { ->applyTo($build); if (!isset($build['#cache']['keys'])) { - $configuration['_wrapper'] = $wrapper; - $configuration_hash = hash('sha256', serialize($configuration)); - $build['#cache']['keys'] = ['twig_tweak_block', $id, $configuration_hash]; + $build['#cache']['keys'] = [ + 'twig_tweak_block', + $id, + '[configuration]=' . hash('sha256', serialize($configuration)), + '[wrapper]=' . (int) $wrapper, + ]; } return $build; diff --git a/tests/src/Kernel/BlockViewBuilderTest.php b/tests/src/Kernel/BlockViewBuilderTest.php index af30454..def9c13 100644 --- a/tests/src/Kernel/BlockViewBuilderTest.php +++ b/tests/src/Kernel/BlockViewBuilderTest.php @@ -65,7 +65,8 @@ final class BlockViewBuilderTest extends KernelTestBase { 'keys' => [ 'twig_tweak_block', '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['#configuration']['label'] = 'Example'; $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('

Example

Bar
', $this->renderPlain($build)); @@ -98,7 +104,8 @@ final class BlockViewBuilderTest extends KernelTestBase { 'keys' => [ 'twig_tweak_block', 'twig_tweak_test_foo', - '82b254ef229c95f336386ee50454e0cc56705e97c1991d68fe9afdb1fb401f3a', + '[configuration]=04c46ea912d2866a3a36c67326da1ef38f1c93cc822d6c45e1639f3decdebbdc', + '[wrapper]=0', ], ], ]; @@ -116,7 +123,8 @@ final class BlockViewBuilderTest extends KernelTestBase { 'keys' => [ 'twig_tweak_block', 'twig_tweak_test_foo', - '9ef25a303eb97a01011ea20c50e731590c000f8bc6196241020fc118cce68180', + '[configuration]=04c46ea912d2866a3a36c67326da1ef38f1c93cc822d6c45e1639f3decdebbdc', + '[wrapper]=1', ], ], ];