From 56f75be0b1fd08f17346b757845406166b9f878e Mon Sep 17 00:00:00 2001 From: Louis Fortunier Date: Thu, 22 Aug 2024 18:10:54 +0200 Subject: [PATCH] Add `condition` parameter default true on `sonata_helper.html.twig` -> `crud_action` macro to add condition on action display --- CHANGELOG_add_condition_macro_crud_action.md | 2 ++ templates/macros/sonata_helper.html.twig | 26 +++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 CHANGELOG_add_condition_macro_crud_action.md diff --git a/CHANGELOG_add_condition_macro_crud_action.md b/CHANGELOG_add_condition_macro_crud_action.md new file mode 100644 index 0000000..f1d918e --- /dev/null +++ b/CHANGELOG_add_condition_macro_crud_action.md @@ -0,0 +1,2 @@ +### Add +- Add `condition` parameter default true on `sonata_helper.html.twig` -> `crud_action` macro to add condition on action display diff --git a/templates/macros/sonata_helper.html.twig b/templates/macros/sonata_helper.html.twig index 2df9ed1..085e414 100644 --- a/templates/macros/sonata_helper.html.twig +++ b/templates/macros/sonata_helper.html.twig @@ -1,17 +1,19 @@ {% trans_default_domain 'admin' %} -{% macro crud_action(object, action, icon) %} - {% set url = admin.generateObjectUrl(action, object) %} - {% set label = ('action.' ~ action|u.snake)|trans %} - {% if admin.isCurrentRoute('list') %} - - - - {% else %} -
  • - - {{ label }} +{% macro crud_action(object, action, icon, condition = true) %} + {% if condition %} + {% set url = admin.generateObjectUrl(action, object) %} + {% set label = ('action.' ~ action|u.snake)|trans %} + {% if admin.isCurrentRoute('list') %} + + -
  • + {% else %} +
  • + + {{ label }} + +
  • + {% endif %} {% endif %} {% endmacro %}