diff --git a/composer.json b/composer.json index 7b74a17d6..567925e27 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,8 @@ "phpunit/phpunit": "^10.0", "rector/rector": "^0.18.2", "sylius-labs/coding-standard": "^4.4", - "sylius/grid-bundle": "^1.13", + "sylius/grid": "*@dev", + "sylius/grid-bundle": "*@dev", "symfony/console": "^6.4 || ^7.1", "symfony/css-selector": "^6.4 || ^7.1", "symfony/dependency-injection": "^6.4 || ^7.1", diff --git a/src/Bundle/Grid/Renderer/TwigGridRenderer.php b/src/Bundle/Grid/Renderer/TwigGridRenderer.php index 7d541873c..cd86772a2 100644 --- a/src/Bundle/Grid/Renderer/TwigGridRenderer.php +++ b/src/Bundle/Grid/Renderer/TwigGridRenderer.php @@ -67,7 +67,10 @@ public function renderAction(GridViewInterface $gridView, Action $action, $data } $type = $action->getType(); - if (!isset($this->actionTemplates[$type])) { + $template = method_exists($action, 'getTemplate') ? $action->getTemplate() : null; + $template ??= $this->actionTemplates[$type] ?? null; + + if (null === $template) { throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type)); } @@ -77,7 +80,7 @@ public function renderAction(GridViewInterface $gridView, Action $action, $data $data, ); - return $this->twig->render($this->actionTemplates[$type], [ + return $this->twig->render($template, [ 'grid' => $gridView, 'action' => $action, 'data' => $data, diff --git a/src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php b/src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php index 309a7c21a..3d27a2c09 100644 --- a/src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php +++ b/src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php @@ -81,6 +81,7 @@ function it_throws_an_exception_if_template_is_not_configured_for_given_action_t ResourceGridView $gridView, Action $action, ): void { + $action->getOptions()->willReturn([]); $action->getType()->willReturn('foo'); $this diff --git a/tests/Application/src/Subscription/Grid/SubscriptionGrid.php b/tests/Application/src/Subscription/Grid/SubscriptionGrid.php index bfe7f6cf7..caa5b5c3b 100644 --- a/tests/Application/src/Subscription/Grid/SubscriptionGrid.php +++ b/tests/Application/src/Subscription/Grid/SubscriptionGrid.php @@ -51,7 +51,8 @@ public function buildGrid(GridBuilderInterface $gridBuilder): void ) ->addActionGroup( ItemActionGroup::create( - ShowAction::create(), + ShowAction::create() + ->setTemplate('subscription/grid/action/show.html.twig'), UpdateAction::create(), DeleteAction::create(), Action::create('accept', 'apply_transition') diff --git a/tests/Application/src/Tests/Controller/SubscriptionUiTest.php b/tests/Application/src/Tests/Controller/SubscriptionUiTest.php index a7f9d725d..c467c6a8a 100644 --- a/tests/Application/src/Tests/Controller/SubscriptionUiTest.php +++ b/tests/Application/src/Tests/Controller/SubscriptionUiTest.php @@ -65,12 +65,12 @@ public function it_allows_browsing_subscriptions(): void } $this->assertStringContainsString('doc.brown@bttf.com', $content); - $this->assertStringContainsString(sprintf('Show', $docBrownSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('Show', $docBrownSubscription->getId()), $content); $this->assertStringContainsString(sprintf('Edit', $docBrownSubscription->getId()), $content); $this->assertStringContainsString(sprintf('
', $docBrownSubscription->getId()), $content); $this->assertStringContainsString('biff.tannen@bttf.com', $content); - $this->assertStringContainsString(sprintf('Show', $biffTannenSubscription->getId()), $content); + $this->assertStringContainsString(sprintf('Show', $biffTannenSubscription->getId()), $content); $this->assertStringContainsString(sprintf('Edit', $biffTannenSubscription->getId()), $content); $this->assertStringContainsString(sprintf('', $biffTannenSubscription->getId()), $content); } diff --git a/tests/Application/templates/subscription/grid/action/show.html.twig b/tests/Application/templates/subscription/grid/action/show.html.twig new file mode 100644 index 000000000..68def01d8 --- /dev/null +++ b/tests/Application/templates/subscription/grid/action/show.html.twig @@ -0,0 +1,3 @@ +{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('show')), options.link.parameters|default({'id': data.id}))) %} + +Show