From 0fa3e0caead3277e45cfe7953a803c266ed4fb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateu=20Aguil=C3=B3=20Bosch?= Date: Mon, 25 May 2026 17:27:00 +0200 Subject: [PATCH] fix: read block config from correct path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The form nests the target block's config under target_block.config.block_config, but validate and submit read from target_block.config — returning the wrapper array (with block_config, context_mapping, no_config keys) instead of actual plugin configuration. Nothing persists. --- src/Service/TargetBlockFormProcessor.php | 4 ++-- tests/src/Unit/TargetBlockFormProcessorTest.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Service/TargetBlockFormProcessor.php b/src/Service/TargetBlockFormProcessor.php index 2748d29..dfcdc70 100644 --- a/src/Service/TargetBlockFormProcessor.php +++ b/src/Service/TargetBlockFormProcessor.php @@ -121,7 +121,7 @@ public function buildTargetBlockConfigurationForm(string $plugin_id, array $conf public function validateTargetBlock(FormStateInterface $form_state, array $configuration): void { $target_block_plugin = $form_state->getValue(['target_block', 'id']); if (!empty($target_block_plugin)) { - $block_config = $form_state->getValue(['target_block', 'config']) ?? $configuration['target_block']['config'] ?? []; + $block_config = $form_state->getValue(['target_block', 'config', 'block_config']) ?? $configuration['target_block']['config'] ?? []; try { $this->blockManager->createInstance($target_block_plugin, $block_config); @@ -149,7 +149,7 @@ public function submitTargetBlock(FormStateInterface $form_state): array { $configuration['target_block']['id'] = $target_plugin_id; if (!empty($target_plugin_id)) { - $block_config = $form_state->getValue(['target_block', 'config']) ?? []; + $block_config = $form_state->getValue(['target_block', 'config', 'block_config']) ?? []; try { $target_block = $this->blockManager->createInstance($target_plugin_id, $block_config); diff --git a/tests/src/Unit/TargetBlockFormProcessorTest.php b/tests/src/Unit/TargetBlockFormProcessorTest.php index 27a1081..2a4bb8b 100644 --- a/tests/src/Unit/TargetBlockFormProcessorTest.php +++ b/tests/src/Unit/TargetBlockFormProcessorTest.php @@ -261,7 +261,7 @@ public function testValidateTargetBlockValid(): void { if ($key === ['target_block', 'id']) { return 'valid_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return ['some_config' => 'value']; } $this->fail('Unexpected getValue call with key: ' . print_r($key, TRUE)); @@ -300,7 +300,7 @@ public function testValidateTargetBlockInvalid(): void { if ($key === ['target_block', 'id']) { return 'invalid_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return []; } $this->fail('Unexpected getValue call with key: ' . print_r($key, TRUE)); @@ -368,7 +368,7 @@ public function testValidateTargetBlockConfigurationFallback(): void { if ($key === ['target_block', 'id']) { return 'test_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return NULL; } $this->fail('Unexpected getValue call with key: ' . print_r($key, TRUE)); @@ -406,7 +406,7 @@ public function testSubmitTargetBlockSimple(): void { if ($key === ['target_block', 'id']) { return 'simple_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return ['block_setting' => 'value']; } $this->fail('Unexpected getValue call with key: ' . print_r($key, TRUE)); @@ -453,7 +453,7 @@ public function testSubmitTargetBlockConfigurable(): void { if ($key === ['target_block', 'id']) { return 'configurable_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return ['user_setting' => 'user_value']; } // @phpstan-ignore-next-line @@ -500,7 +500,7 @@ public function testSubmitTargetBlockContextAware(): void { if ($key === ['target_block', 'id']) { return 'context_aware_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return ['setting' => 'value']; } // @phpstan-ignore-next-line @@ -575,7 +575,7 @@ public function testSubmitTargetBlockPluginException(): void { if ($key === ['target_block', 'id']) { return 'invalid_block'; } - if ($key === ['target_block', 'config']) { + if ($key === ['target_block', 'config', 'block_config']) { return ['setting' => 'value']; } $this->fail('Unexpected getValue call with key: ' . print_r($key, TRUE));