Skip to content

Commit

Permalink
Add condition parameter default true on sonata_helper.html.twig -…
Browse files Browse the repository at this point in the history
…> `crud_action` macro to add condition on action display
  • Loading branch information
Louis Fortunier committed Aug 22, 2024
1 parent d37f233 commit 56f75be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_add_condition_macro_crud_action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Add
- Add `condition` parameter default true on `sonata_helper.html.twig` -> `crud_action` macro to add condition on action display
26 changes: 14 additions & 12 deletions templates/macros/sonata_helper.html.twig
Original file line number Diff line number Diff line change
@@ -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') %}
<a href="{{ url }}" class="btn btn-xs btn-default" title="{{ label }}">
<i class="{{ icon }}"></i>
</a>
{% else %}
<li>
<a class="sonata-action-element" href="{{ url }}">
<i class="{{ icon }}"></i> {{ 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') %}
<a href="{{ url }}" class="btn btn-xs btn-default" title="{{ label }}">
<i class="{{ icon }}"></i>
</a>
</li>
{% else %}
<li>
<a class="sonata-action-element" href="{{ url }}">
<i class="{{ icon }}"></i> {{ label }}
</a>
</li>
{% endif %}
{% endif %}
{% endmacro %}

0 comments on commit 56f75be

Please sign in to comment.