diff --git a/src/View/BlockViewBuilder.php b/src/View/BlockViewBuilder.php
index 957b396..ef54db7 100644
--- a/src/View/BlockViewBuilder.php
+++ b/src/View/BlockViewBuilder.php
@@ -135,6 +135,7 @@ class BlockViewBuilder {
if ($wrapper && !Element::isEmpty($build['content'])) {
$build += [
'#theme' => 'block',
+ '#id' => $configuration['id'] ?? $id,
'#attributes' => [],
'#contextual_links' => [],
'#configuration' => $block_plugin->getConfiguration(),
diff --git a/tests/src/Kernel/BlockViewBuilderTest.php b/tests/src/Kernel/BlockViewBuilderTest.php
index def9c13..4ed03d2 100644
--- a/tests/src/Kernel/BlockViewBuilderTest.php
+++ b/tests/src/Kernel/BlockViewBuilderTest.php
@@ -46,6 +46,7 @@ final class BlockViewBuilderTest extends KernelTestBase {
],
],
'#theme' => 'block',
+ '#id' => 'twig_tweak_test_foo',
'#attributes' => [],
'#contextual_links' => [],
'#configuration' => [
@@ -71,21 +72,28 @@ final class BlockViewBuilderTest extends KernelTestBase {
],
];
self::assertSame($expected_build, $build);
- self::assertSame('
Foo
', $this->renderPlain($build));
+ self::assertSame('Foo
', $this->renderPlain($build));
// -- Non-default configuration.
- $build = $view_builder->build('twig_tweak_test_foo', ['content' => 'Bar', 'label' => 'Example']);
+ $configuration = [
+ 'content' => 'Bar',
+ 'label' => 'Example',
+ 'id' => 'example',
+ ];
+ $build = $view_builder->build('twig_tweak_test_foo', $configuration);
$expected_build['content']['#markup'] = 'Bar';
$expected_build['#configuration']['label'] = 'Example';
$expected_build['#configuration']['content'] = 'Bar';
+ $expected_build['#configuration']['id'] = 'example';
+ $expected_build['#id'] = 'example';
$expected_build['#cache']['keys'] = [
'twig_tweak_block',
'twig_tweak_test_foo',
- '[configuration]=373b0811b355fa153ac8934c897a021697ff6e848f00b85e711d36212b77a958',
+ '[configuration]=8e53716fcf7e5d5c45effd55e9b2a267bbaf333f7253766f572d58e4f7991b36',
'[wrapper]=1',
];
self::assertSame($expected_build, $build);
- self::assertSame('Example
Bar', $this->renderPlain($build));
+ self::assertSame('Example
Bar', $this->renderPlain($build));
// -- Without wrapper.
$build = $view_builder->build('twig_tweak_test_foo', [], FALSE);