From bbe2059c2f8807dc04a4f669060a638d9d3ef557 Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Fri, 12 Jun 2026 11:57:13 +0000 Subject: [PATCH 1/2] Deliver the content between a shortcode to the controller --- src/Handler/EmbeddedShortcodeHandler.php | 2 +- .../Controller/ShortcodeTestController.php | 4 ++-- .../EmbeddedShortcodeHandlerTest.php | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index 89626af..7c089af 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -68,7 +68,7 @@ public function __invoke(ShortcodeInterface $shortcode) try { return $this->fragmentHandler->render( - new ControllerReference($this->controllerName, $shortcode->getParameters()), + new ControllerReference($this->controllerName, [...['content' => $shortcode->getContent()], ...$shortcode->getParameters()]), $this->renderer ); } catch (Throwable $exception) { diff --git a/tests/Fixtures/Controller/ShortcodeTestController.php b/tests/Fixtures/Controller/ShortcodeTestController.php index 1b13ff4..73001e9 100644 --- a/tests/Fixtures/Controller/ShortcodeTestController.php +++ b/tests/Fixtures/Controller/ShortcodeTestController.php @@ -6,8 +6,8 @@ class ShortcodeTestController { - public function test(?string $foo = null): Response + public function test(?string $foo = null, ?string $content = null): Response { - return new Response('test'.($foo ? ' foo='.$foo : '')); + return new Response('test'.($foo ? ' foo='.$foo : '').($content !== null ? ' content='.$content : '')); } } diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index cf58a69..d506249 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -70,6 +70,24 @@ public function invokable_controller_can_be_used(): void self::assertSame('invokable-controller-response', $this->processShortcodes('

[test-config-invokable]

')); } + #[Test] + public function content_between_tags_is_passed_to_controller(): void + { + self::assertSame('test content=Hello', $this->processShortcodes('[test-config-inline]Hello[/test-config-inline]')); + } + + #[Test] + public function content_is_null_for_self_closing_shortcode(): void + { + self::assertSame('test', $this->processShortcodes('[test-config-inline]')); + } + + #[Test] + public function content_attribute_overrides_content_between_tags(): void + { + self::assertSame('test content=override', $this->processShortcodes('[test-config-inline content=override]Hello[/test-config-inline]')); + } + #[DataProvider('provideControllerNames')] #[Test] public function throws_exception_on_invalid_controller_names(string $controllerName): void From 6de2a7bea81854f1a924536913607ec5798a425c Mon Sep 17 00:00:00 2001 From: FabianSchmick <17527958+FabianSchmick@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:57:40 +0000 Subject: [PATCH 2/2] Fix CS with PHP-CS-Fixer --- tests/Fixtures/Controller/ShortcodeTestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Fixtures/Controller/ShortcodeTestController.php b/tests/Fixtures/Controller/ShortcodeTestController.php index 73001e9..9a50d3e 100644 --- a/tests/Fixtures/Controller/ShortcodeTestController.php +++ b/tests/Fixtures/Controller/ShortcodeTestController.php @@ -8,6 +8,6 @@ class ShortcodeTestController { public function test(?string $foo = null, ?string $content = null): Response { - return new Response('test'.($foo ? ' foo='.$foo : '').($content !== null ? ' content='.$content : '')); + return new Response('test'.($foo ? ' foo='.$foo : '').(null !== $content ? ' content='.$content : '')); } }