Skip to content
Draft
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/Bundle/Grid/Renderer/TwigGridRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/Application/src/Subscription/Grid/SubscriptionGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/Application/src/Tests/Controller/SubscriptionUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function it_allows_browsing_subscriptions(): void
}

$this->assertStringContainsString('<td>doc.brown@bttf.com</td>', $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s">Show</a>', $docBrownSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s" data-custom-show>Show</a>', $docBrownSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s/edit">Edit</a>', $docBrownSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s/delete" method="post">', $docBrownSubscription->getId()), $content);

$this->assertStringContainsString('<td>biff.tannen@bttf.com</td>', $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s">Show</a>', $biffTannenSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s" data-custom-show>Show</a>', $biffTannenSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<a href="/admin/subscriptions/%s/edit">Edit</a>', $biffTannenSubscription->getId()), $content);
$this->assertStringContainsString(sprintf('<form action="/admin/subscriptions/%s/delete" method="post">', $biffTannenSubscription->getId()), $content);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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}))) %}

<a href="{{ path }}" data-custom-show>Show</a>