Skip to content

Commit b21d623

Browse files
committed
Allow to define a template in action options
1 parent e33f7a6 commit b21d623

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Bundle/Grid/Renderer/TwigGridRenderer.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public function renderAction(GridViewInterface $gridView, Action $action, $data
6767
}
6868

6969
$type = $action->getType();
70-
if (!isset($this->actionTemplates[$type])) {
70+
$template = method_exists($action, 'getTemplate') ? $action->getTemplate() : null;
71+
$template ??= $this->actionTemplates[$type] ?? null;
72+
73+
if (null === $template) {
7174
throw new \InvalidArgumentException(sprintf('Missing template for action type "%s".', $type));
7275
}
7376

@@ -77,7 +80,7 @@ public function renderAction(GridViewInterface $gridView, Action $action, $data
7780
$data,
7881
);
7982

80-
return $this->twig->render($this->actionTemplates[$type], [
83+
return $this->twig->render($template, [
8184
'grid' => $gridView,
8285
'action' => $action,
8386
'data' => $data,

src/Bundle/spec/Grid/Renderer/TwigGridRendererSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function it_throws_an_exception_if_template_is_not_configured_for_given_action_t
8181
ResourceGridView $gridView,
8282
Action $action,
8383
): void {
84+
$action->getOptions()->willReturn([]);
8485
$action->getType()->willReturn('foo');
8586

8687
$this

0 commit comments

Comments
 (0)