add crud option to hide actions

This commit is contained in:
Simon Vieille 2021-08-20 11:34:53 +02:00
parent 5e21a23cb1
commit dc69c031e6
2 changed files with 43 additions and 26 deletions

View file

@ -28,6 +28,7 @@ class CrudConfiguration
protected array $isSortableCollection = [];
protected string $sortableCollectionProperty = 'sortOrder';
protected ?string $defaultLocale = null;
protected bool $showActions = true;
protected static $self;
@ -314,4 +315,16 @@ class CrudConfiguration
{
return $this->sortableCollectionProperty;
}
public function setShowActions(bool $showActions): self
{
$this->showActions = $showActions;
return $this;
}
public function getShowActions(): bool
{
return $this->showActions;
}
}

View file

@ -139,9 +139,11 @@
</th>
{% endblock %}
{% endfor %}
<th class="crud-action-column col-2 miw-100 text-right">
{{ 'Actions'|trans }}
</th>
{% if configuration.showActions %}
<th class="crud-action-column col-2 miw-100 text-right">
{{ 'Actions'|trans }}
</th>
{% endif %}
</tr>
</thead>
{% endblock %}
@ -205,34 +207,36 @@
</td>
{% endfor %}
<td class="crud-action-column col-2 miw-200 text-right">
{% block list_item_actions_before %}{% endblock %}
{% if configuration.showActions %}
<td class="crud-action-column col-2 miw-200 text-right">
{% block list_item_actions_before %}{% endblock %}
{% if configuration.action(context, 'show', true) %}
<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, 'show', true) %}
<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) %}
<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, 'edit', true) %}
<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) %}
<button type="submit" form="form-delete-{{ item.id }}" class="btn btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
{% if configuration.action(context, 'delete', true) %}
<button type="submit" form="form-delete-{{ item.id }}" class="btn btn-sm btn-danger">
<span class="fa fa-trash"></span>
</button>
<form method="post" action="{{ path(configuration.pageRoute('delete'), {entity: item.id}|merge(configuration.pageRouteParams('delete'))) }}" id="form-delete-{{ item.id }}" data-form-confirm>
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}">
</form>
{% endif %}
<form method="post" action="{{ path(configuration.pageRoute('delete'), {entity: item.id}|merge(configuration.pageRouteParams('delete'))) }}" id="form-delete-{{ item.id }}" data-form-confirm>
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ item.id) }}">
</form>
{% endif %}
{% block list_item_actions_after %}{% endblock %}
</td>
{% block list_item_actions_after %}{% endblock %}
</td>
{% endif %}
</tr>
{% endblock %}