diff --git a/CHANGELOG.md b/CHANGELOG.md index b44316453..8d5c69523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CRUD/Resolver/Resolver.php b/CRUD/Resolver/Resolver.php index 86e0ecbca..64aeb61bc 100644 --- a/CRUD/Resolver/Resolver.php +++ b/CRUD/Resolver/Resolver.php @@ -93,4 +93,10 @@ class Resolver '_'. $action); } + + public function hasAction($crudName, $action) + { + return \array_key_exists($action, + $this->crudConfig[$crudName]['actions']); + } } diff --git a/CRUD/Templating/TwigCRUDResolver.php b/CRUD/Templating/TwigCRUDResolver.php index f962038b4..a593b08b0 100644 --- a/CRUD/Templating/TwigCRUDResolver.php +++ b/CRUD/Templating/TwigCRUDResolver.php @@ -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); + } } diff --git a/Resources/views/CRUD/_edit_content.html.twig b/Resources/views/CRUD/_edit_content.html.twig index c1a1c0052..77b794ce9 100644 --- a/Resources/views/CRUD/_edit_content.html.twig +++ b/Resources/views/CRUD/_edit_content.html.twig @@ -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) %}
  • {% 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) %}
  • {% endif %} + {% endif %} {% endblock content_form_actions_view %} {% block content_form_actions_save_and_close %}
  • diff --git a/Resources/views/CRUD/_view_content.html.twig b/Resources/views/CRUD/_view_content.html.twig index 2febcc4a6..f56a00e1b 100644 --- a/Resources/views/CRUD/_view_content.html.twig +++ b/Resources/views/CRUD/_view_content.html.twig @@ -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) %}
  • @@ -30,8 +31,10 @@
  • {% 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) %}
  • @@ -39,8 +42,10 @@
  • {% 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) %}
  • @@ -48,6 +53,7 @@
  • {% endif %} + {% endif %} {% endblock content_view_actions_edit_link %} {% block content_view_actions_after %}{% endblock %}