CrudConfiguration::setAction can receive a callable instead of a boolean in 'enabled' param
This commit is contained in:
parent
82f4f63fe4
commit
443ccabd0b
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace App\Core\Crud;
|
||||
|
||||
use App\Core\Crud\Exception\CrudConfigurationException;
|
||||
|
||||
/**
|
||||
* class CrudConfiguration.
|
||||
*
|
||||
|
@ -109,7 +107,7 @@ class CrudConfiguration
|
|||
|
||||
/* -- */
|
||||
|
||||
public function setAction(string $page, string $action, bool $enabled): self
|
||||
public function setAction(string $page, string $action, bool|callable $enabled): self
|
||||
{
|
||||
if (!isset($this->actions[$page])) {
|
||||
$this->actions[$page] = [];
|
||||
|
@ -120,9 +118,20 @@ class CrudConfiguration
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getAction(string $page, string $action, bool $default = true)
|
||||
public function getAction(string $page, string $action, bool $default = true, array $callableParamaters = [])
|
||||
{
|
||||
return $this->actions[$page][$action] ?? $default;
|
||||
if (!isset($this->actions[$page][$action])) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (is_bool($this->actions[$page][$action])) {
|
||||
return $this->actions[$page][$action];
|
||||
}
|
||||
|
||||
return call_user_func_array(
|
||||
$this->actions[$page][$action],
|
||||
$callableParamaters
|
||||
);
|
||||
}
|
||||
|
||||
public function setBatchAction(string $page, string $action, string $label, callable $callback): self
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if configuration.action(context, 'show', true) %}
|
||||
{% if configuration.action(context, 'show', true, [entity]) %}
|
||||
<a href="{{ path(configuration.pageRoute('show'), {entity: entity.id}|merge(configuration.pageRouteParams('show'))) }}" class="btn btn-secondary">
|
||||
<span class="fa fa-eye pr-1"></span>
|
||||
{{ configuration.actionTitle(context, 'show', 'Show')|trans|build_string(entity) }}
|
||||
|
@ -42,7 +42,7 @@
|
|||
{% set header_actions_dropdown_menu = '' %}
|
||||
{% endif %}
|
||||
|
||||
{% if configuration.action(context, 'delete', true) %}
|
||||
{% if configuration.action(context, 'delete', true, [entity]) %}
|
||||
{% set item %}
|
||||
<button type="submit" form="form-delete" class="dropdown-item">
|
||||
{{ configuration.actionTitle(context, 'delete', 'Delete')|trans|build_string(entity) }}
|
||||
|
@ -86,7 +86,7 @@
|
|||
</form>
|
||||
{% endblock %}
|
||||
|
||||
{% if configuration.action(context, 'delete', true) %}
|
||||
{% if configuration.action(context, 'delete', true, [entity]) %}
|
||||
<form method="post" action="{{ path(configuration.pageRoute('delete'), {entity: entity.id}|merge(configuration.pageRouteParams('delete'))) }}" id="form-delete" data-form-confirm>
|
||||
<input type="hidden" name="_method" value="DELETE">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ entity.id) }}">
|
||||
|
|
|
@ -174,9 +174,9 @@
|
|||
|
||||
{% block list_item %}
|
||||
{%- set dbClick %}
|
||||
{% if configuration.action(context, 'show', true) %}
|
||||
{% if configuration.action(context, 'show', true, [item]) %}
|
||||
{{ path(configuration.pageRoute('show'), {entity: item.id}|merge(configuration.pageRouteParams('show'))) }}
|
||||
{% elseif configuration.action(context, 'edit', true) %}
|
||||
{% elseif configuration.action(context, 'edit', true, [item]) %}
|
||||
{{ path(configuration.pageRoute('edit'), {entity: item.id}|merge(configuration.pageRouteParams('show'))) }}
|
||||
{% endif %}
|
||||
{% endset -%}
|
||||
|
@ -211,19 +211,19 @@
|
|||
<td class="crud-action-column col-2 miw-200 text-right">
|
||||
{% block list_item_actions_before %}{% endblock %}
|
||||
|
||||
{% if configuration.action(context, 'show', true) %}
|
||||
{% if configuration.action(context, 'show', true, [item]) %}
|
||||
<a href="{{ path(configuration.pageRoute('show'), {entity: item.id}|merge(configuration.pageRouteParams('show'))) }}" class="btn btn-sm btn-secondary mr-1">
|
||||
<span class="fa fa-eye"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if configuration.action(context, 'edit', true) %}
|
||||
{% if configuration.action(context, 'edit', true, [item]) %}
|
||||
<a href="{{ path(configuration.pageRoute('edit'), {entity: item.id}|merge(configuration.pageRouteParams('edit'))) }}" class="btn btn-sm btn-primary mr-1">
|
||||
<span class="fa fa-edit"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if configuration.action(context, 'delete', true) %}
|
||||
{% if configuration.action(context, 'delete', true, [item]) %}
|
||||
<button type="submit" form="form-delete-{{ item.id }}" class="btn btn-sm btn-danger">
|
||||
<span class="fa fa-trash"></span>
|
||||
</button>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if configuration.action(context, 'edit', true) %}
|
||||
{% if configuration.action(context, 'edit', true, [entity]) %}
|
||||
<a href="{{ path(configuration.pageRoute('edit'), {entity: entity.id}) }}" class="btn btn-primary">
|
||||
<span class="fa fa-edit pr-1"></span>
|
||||
|
||||
|
|
Loading…
Reference in a new issue