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;
|
namespace App\Core\Crud;
|
||||||
|
|
||||||
use App\Core\Crud\Exception\CrudConfigurationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class CrudConfiguration.
|
* 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])) {
|
if (!isset($this->actions[$page])) {
|
||||||
$this->actions[$page] = [];
|
$this->actions[$page] = [];
|
||||||
|
@ -120,9 +118,20 @@ class CrudConfiguration
|
||||||
return $this;
|
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
|
public function setBatchAction(string $page, string $action, string $label, callable $callback): self
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% 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">
|
<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>
|
<span class="fa fa-eye pr-1"></span>
|
||||||
{{ configuration.actionTitle(context, 'show', 'Show')|trans|build_string(entity) }}
|
{{ configuration.actionTitle(context, 'show', 'Show')|trans|build_string(entity) }}
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
{% set header_actions_dropdown_menu = '' %}
|
{% set header_actions_dropdown_menu = '' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if configuration.action(context, 'delete', true) %}
|
{% if configuration.action(context, 'delete', true, [entity]) %}
|
||||||
{% set item %}
|
{% set item %}
|
||||||
<button type="submit" form="form-delete" class="dropdown-item">
|
<button type="submit" form="form-delete" class="dropdown-item">
|
||||||
{{ configuration.actionTitle(context, 'delete', 'Delete')|trans|build_string(entity) }}
|
{{ configuration.actionTitle(context, 'delete', 'Delete')|trans|build_string(entity) }}
|
||||||
|
@ -86,7 +86,7 @@
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% 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>
|
<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="_method" value="DELETE">
|
||||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ entity.id) }}">
|
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ entity.id) }}">
|
||||||
|
|
|
@ -174,9 +174,9 @@
|
||||||
|
|
||||||
{% block list_item %}
|
{% block list_item %}
|
||||||
{%- set dbClick %}
|
{%- 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'))) }}
|
{{ 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'))) }}
|
{{ path(configuration.pageRoute('edit'), {entity: item.id}|merge(configuration.pageRouteParams('show'))) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endset -%}
|
{% endset -%}
|
||||||
|
@ -211,19 +211,19 @@
|
||||||
<td class="crud-action-column col-2 miw-200 text-right">
|
<td class="crud-action-column col-2 miw-200 text-right">
|
||||||
{% block list_item_actions_before %}{% endblock %}
|
{% 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">
|
<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>
|
<span class="fa fa-eye"></span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% 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">
|
<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>
|
<span class="fa fa-edit"></span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% 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">
|
<button type="submit" form="form-delete-{{ item.id }}" class="btn btn-sm btn-danger">
|
||||||
<span class="fa fa-trash"></span>
|
<span class="fa fa-trash"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% 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">
|
<a href="{{ path(configuration.pageRoute('edit'), {entity: entity.id}) }}" class="btn btn-primary">
|
||||||
<span class="fa fa-edit pr-1"></span>
|
<span class="fa fa-edit pr-1"></span>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue