[CRUD] check that action exists before inserting them in edit and view template

This commit is contained in:
Julien Fastré 2020-04-21 12:33:36 +02:00
parent d4b498e2be
commit 1e06393a7d
5 changed files with 25 additions and 2 deletions

View File

@ -112,4 +112,4 @@ Master branch
- [translation] in french, replace "Modifier" by "Enregistrer" in the edit form
- [chill entity render] fix error when fallback to default entity render (usage of `__toString()`)
- [CRUD] add step delete
- [CRUD] check that action exists before inserting them in edit and view template

View File

@ -93,4 +93,10 @@ class Resolver
'_'.
$action);
}
public function hasAction($crudName, $action)
{
return \array_key_exists($action,
$this->crudConfig[$crudName]['actions']);
}
}

View File

@ -47,7 +47,9 @@ class TwigCRUDResolver extends AbstractExtension
{
return [
new TwigFunction('chill_crud_config', [$this, 'getConfig'],
['is_safe' => 'html'])
['is_safe' => 'html']),
new TwigFunction('chill_crud_action_exists', [$this, 'hasAction'],
[]),
];
}
@ -55,5 +57,10 @@ class TwigCRUDResolver extends AbstractExtension
{
return $this->resolver->getConfigValue($configKey, $crudName, $action);
}
public function hasAction($crudName, $action)
{
return $this->resolver->hasAction($crudName, $action);
}
}

View File

@ -23,18 +23,22 @@
{% endblock %}
{% block content_form_actions_before %}{% endblock %}
{% block content_form_actions_delete %}
{% if chill_crud_action_exists(crud_name, 'delete') %}
{% if is_granted(chill_crud_config('role', crud_name, 'delete'), entity) %}
<li class="">
<a class="sc-button bt-small bt-delete" href="{{ chill_path_add_return_path('chill_crud_'~crud_name~'_delete', { 'id': entity.id }) }}"></a>
</li>
{% endif %}
{% endif %}
{% endblock content_form_actions_delete %}
{% block content_form_actions_view %}
{% if chill_crud_action_exists(crud_name, 'view') %}
{% if is_granted(chill_crud_config('role', crud_name, 'view'), entity) %}
<li class="">
<a class="sc-button bt-small bt-show" href="{{ chill_path_forward_return_path('chill_crud_'~crud_name~'_view', { 'id': entity.id }) }}"></a>
</li>
{% endif %}
{% endif %}
{% endblock content_form_actions_view %}
{% block content_form_actions_save_and_close %}
<li class="">

View File

@ -23,6 +23,7 @@
{% endblock %}
{% block content_view_actions_before %}{% endblock %}
{% block content_form_actions_delete %}
{% if chill_crud_action_exists(crud_name, 'delete') %}
{% if is_granted(chill_crud_config('role', crud_name, 'delete'), entity) %}
<li class="">
<a class="sc-button bt-delete" href="{{ chill_path_add_return_path('chill_crud_'~crud_name~'_delete', { 'id': entity.id }) }}">
@ -30,8 +31,10 @@
</a>
</li>
{% endif %}
{% endif %}
{% endblock content_form_actions_delete %}
{% block content_view_actions_duplicate_link %}
{% if chill_crud_action_exists(crud_name, 'new') %}
{% if is_granted(chill_crud_config('role', crud_name, 'new'), entity) %}
<li>
<a class="sc-button bt-duplicate" href="{{ chill_path_add_return_path('chill_crud_'~crud_name~'_new', { 'duplicate_id': entity.id, 'duplicate': true }) }}">
@ -39,8 +42,10 @@
</a>
</li>
{% endif %}
{% endif %}
{% endblock content_view_actions_duplicate_link %}
{% block content_view_actions_edit_link %}
{% if chill_crud_action_exists(crud_name, 'edit') %}
{% if is_granted(chill_crud_config('role', crud_name, 'edit'), entity) %}
<li>
<a class="sc-button bt-edit" href="{{ chill_path_forward_return_path('chill_crud_'~crud_name~'_edit', { 'id': entity.id }) }}">
@ -48,6 +53,7 @@
</a>
</li>
{% endif %}
{% endif %}
{% endblock content_view_actions_edit_link %}
{% block content_view_actions_after %}{% endblock %}
</ul>