{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #} {% set main_menu_contents %} {% block main_menu_before %}{% endblock %} {% block main_menu %} {# the main menu is a flat list of items where 'section' items mark the start of a new group #} {% set menu_groups = [] %} {% set current_group = {section: null, items: []} %} {% for menuItem in ea().mainMenu.items %} {% if menuItem.isMenuSection %} {% if current_group.section is not null or current_group.items is not empty %} {% set menu_groups = menu_groups|merge([current_group]) %} {% endif %} {% set current_group = {section: menuItem, items: []} %} {% else %} {# a submenu can be empty when its items define permissions and the current user can't see any of them; in that case, don't display anything for the submenu #} {% set is_submenu_item_with_no_items = menuItem.type == constant('EasyCorp\\Bundle\\EasyAdminBundle\\Dto\\MenuItemDto::TYPE_SUBMENU') and not menuItem.hasSubItems %} {% if not is_submenu_item_with_no_items %} {% set current_group = current_group|merge({items: current_group.items|merge([menuItem])}) %} {% endif %} {% endif %} {% endfor %} {% if current_group.section is not null or current_group.items is not empty %} {% set menu_groups = menu_groups|merge([current_group]) %} {% endif %} {# badges and submenus are rendered into variables before calling the components because macros (and other template-level constructs) are not available inside the component slots, which are compiled as separate templates #} {% for menu_group in menu_groups %} {% set group_items %} {% for menuItem in menu_group.items %} {% set item_badge %} {%- if menuItem.hasVisibleBadge -%} {{ _self.render_menu_badge(menuItem.badge) }} {%- endif -%} {% endset %} {% set item_submenu %} {% if menuItem.hasSubItems %} {% set submenu_items %} {% for menuSubItem in menuItem.subItems %} {% if menuSubItem.isMenuSection %}
  • {{ menuSubItem.label|trans|raw }}
  • {% else %} {% set subitem_badge %} {%- if menuSubItem.hasVisibleBadge -%} {{ _self.render_menu_badge(menuSubItem.badge) }} {%- endif -%} {% endset %} {{ subitem_badge }} {% endif %} {% endfor %} {% endset %} {{ submenu_items }} {% endif %} {% endset %} {{ item_badge }} {{ item_submenu }} {% endfor %} {% endset %} {% set group_badge %} {%- if menu_group.section and menu_group.section.badge -%} {{ _self.render_menu_badge(menu_group.section.badge) }} {%- endif -%} {% endset %} {% set section_attributes = menu_group.section ? menu_group.section.htmlAttributes : {} %} {{ group_badge }} {{ group_items }} {% endfor %} {% endblock main_menu %} {% block main_menu_after %}{% endblock %} {% endset %} {{ main_menu_contents }} {% macro render_menu_badge(badge) %} {%- set badge_attributes = badge.htmlStyle ? badge.htmlAttributes|merge({style: badge.htmlStyle}) : badge.htmlAttributes -%} {{ badge.content }} {%- endmacro %}