Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Handler/EmbeddedShortcodeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/Controller/ShortcodeTestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 : '').(null !== $content ? ' content='.$content : ''));
}
}
18 changes: 18 additions & 0 deletions tests/Functional/EmbeddedShortcodeHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public function invokable_controller_can_be_used(): void
self::assertSame('invokable-controller-response', $this->processShortcodes('<p>[test-config-invokable]</p>'));
}

#[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
Expand Down
Loading