{% macro render_menu_item(item, translation_domain) %}
{% if item.type == 'divider' %}
{{ item.label|trans(domain = translation_domain) }}
{% else %}
{% set menu_params = { menuIndex: item.menu_index, submenuIndex: item.submenu_index } %}
{% set path =
item.type == 'link' ? item.url :
item.type == 'route' ? path(item.route, item.params) :
item.type == 'entity' ? path('easyadmin', { entity: item.entity, action: 'list' }|merge(menu_params)|merge(item.params)) :
item.type == 'empty' ? '#' : ''
%}
{# if the URL generated for the route belongs to the backend, regenerate
the URL to include the menu_params to display the selected menu item
(this is checked comparing the beginning of the route URL with the backend homepage URL)
#}
{% if item.type == 'route' and (path starts with path('easyadmin')) %}
{% set path = path(item.route, menu_params|merge(item.params)) %}
{% endif %}
<a href="{{ path }}"
class="sidebar-link {{ item.css_class|default('') }}"
{% if item.target|default(false) %}target="{{ item.target }}"{% endif %}
{% if item.rel|default(false) %}rel="{{ item.rel }}"{% endif %}>
{% if item.icon is not empty %}<i class="fa fa-fw {{ item.icon }}"></i>{% endif %}
<span>{{ item.label|trans(domain = translation_domain) }}</span>
{% if item.children|default([]) is not empty %}<i class="fa fa-fw fa-angle-right"></i>{% endif %}
</a>
{% endif %}
{% endmacro %}
{% import _self as helper %}
{% block main_menu_before %}{% endblock %}
{% set _translation_domain = (_entity_config.translation_domain)|default(easyadmin_config('translation_domain'))|default('messages') %}
<nav class="sidebar-nav">
<ul class="in" id="sidebarnav">
{% set _menu_items = easyadmin_config('design.menu') %}
{% block main_menu %}
{% for item in _menu_items %}
{% block menu_item %}
{% set is_selected_menu = app.request.query.get('menuIndex')|default(-1) == item.menu_index %}
{% set is_selected_submenu = is_selected_menu and app.request.query.get('submenuIndex')|default(-1) != -1 %}
{% if easyadmin_is_granted(item.permission) %}
<li class="sidebar-item {{ item.type == 'divider' ? 'nav-small-cap' }} {{ item.children is not empty ? 'treeview' }} {{ is_selected_menu ? 'selected' }} {{ is_selected_submenu ? 'submenu-selected' }}">
{{ helper.render_menu_item(item, _translation_domain) }}
{% if item.children|default([]) is not empty %}
<ul class="collapse first-level base-level-line">
{% for subitem in item.children %}
{% block menu_subitem %}
{% if easyadmin_is_granted(subitem.permission) %}
<li class="sidebar-item {{ subitem.type == 'divider' ? 'header' }} {{ is_selected_menu and app.request.query.get('submenuIndex')|default(-1) == subitem.submenu_index ? 'active' }}">
{{ helper.render_menu_item(subitem, _translation_domain) }}
</li>
{% endif %}
{% endblock menu_subitem %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endif %}
{% endblock menu_item %}
{% endfor %}
{% endblock main_menu %}
</ul>
</nav>
{% block main_menu_after %}{% endblock %}