Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 9563f1b

Browse files
committed
Fix closure on attributes action option
1 parent 1078ccf commit 9563f1b

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Datatable/Column/ActionColumn.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ public function addDataToOutputArray(array &$row)
8181
public function renderSingleField(array &$row)
8282
{
8383
$parameters = array();
84+
$attributes = array();
8485
$values = array();
8586

8687
/** @var Action $action */
8788
foreach ($this->actions as $actionKey => $action) {
8889
$routeParameters = $action->getRouteParameters();
8990
if (is_array($routeParameters)) {
90-
foreach ($routeParameters as $key => $value) {
91+
foreach ($routeParameters as $key => $value) {
9192
if (isset($row[$value])) {
9293
$parameters[$actionKey][$key] = $row[$value];
9394
} else {
@@ -108,8 +109,12 @@ public function renderSingleField(array &$row)
108109
}
109110

110111
$actionAttributes = $action->getAttributes();
111-
if ($actionAttributes instanceof Closure) {
112-
$action->setAttributes(call_user_func($actionAttributes, $row));
112+
if (is_array($actionAttributes)) {
113+
$attributes[$actionKey] = $actionAttributes;
114+
} elseif ($actionAttributes instanceof Closure) {
115+
$attributes[$actionKey] = call_user_func($actionAttributes, $row);
116+
} else {
117+
$attributes[$actionKey] = array();
113118
}
114119

115120
if ($action->isButton()) {
@@ -138,6 +143,7 @@ public function renderSingleField(array &$row)
138143
array(
139144
'actions' => $this->actions,
140145
'route_parameters' => $parameters,
146+
'attributes' => $attributes,
141147
'values' => $values,
142148
'render_if_actions' => $row['sg_datatables_actions'][$this->index],
143149
'start_html_container' => $this->startHtml,

Resources/views/render/action.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
{% endif %}
2121
{% endmacro %}
2222

23-
{% macro attributes(action) %}
24-
{% for key, value in action.attributes %}
23+
{% macro attributes(attributes) %}
24+
{% for key, value in attributes %}
2525
{{ key }}="{{ value }}"
2626
{% endfor %}
2727
{% endmacro %}
@@ -64,13 +64,13 @@
6464
{% if render_if_actions[actionKey] is same as(true) %}
6565
{% if action.button is same as(false) %}
6666
{{ action.startHtml|raw }}
67-
<a {{ macros.href(action, route_parameters[actionKey]) }} {{ macros.attributes(action) }} {{ macros.confirm_dialog(action) }}>
67+
<a {{ macros.href(action, route_parameters[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}>
6868
{{ macros.link_title(action) }}
6969
</a>
7070
{{ action.endHtml|raw }}
7171
{% else %}
7272
{{ action.startHtml|raw }}
73-
<button type="button" {{ macros.value(values[actionKey]) }} {{ macros.attributes(action) }} {{ macros.confirm_dialog(action) }}>
73+
<button type="button" {{ macros.value(values[actionKey]) }} {{ macros.attributes(attributes[actionKey]) }} {{ macros.confirm_dialog(action) }}>
7474
{{ macros.link_title(action) }}
7575
</button>
7676
{{ action.endHtml|raw }}

0 commit comments

Comments
 (0)