{# Template personnalisé pour afficher les rôles de manière ergonomique #}
{% block sonata_all_roles_widget %}
{# Hidden field to store the serialized roles as JSON #}
{# JavaScript sync is handled in assets/js/admin.js #}
{% if roles_by_category is defined %}
{% for categoryName, categoryData in roles_by_category %}
{{ categoryName }}
{% if categoryData.description is defined %}
{{ categoryData.description }}
{% endif %}
{% for roleValue, roleLabel in categoryData.roles %}
{# Check if this role is in the current values (data from database) #}
{% set isChecked = false %}
{% if value is defined and value is not empty %}
{% if roleValue in value %}
{% set isChecked = true %}
{% endif %}
{% endif %}
{% set isAllRights = roleLabel == 'Tous les droits' or roleValue ends with '_ALL' %}
{% endfor %}
{% endfor %}
{% else %}
{# Fallback to default rendering if roles_by_category is not available #}
{{ block('choice_widget_expanded') }}
{% endif %}