{% extends 'knp_menu_base.html.twig' %} {% macro attributes(attributes) %} {% for name, value in attributes %} {%- if value is not none and value is not same as (false) -%} {{- ' %s="%s"'|format(name, value is same as (true) ? name|e : value|e)|raw -}} {%- endif -%} {%- endfor -%} {% endmacro %} {% from _self import attributes as attributes %} {% block compressed_root %} {% apply spaceless %} {{ block('root') }} {% endapply %} {% endblock %} {% block root %} {% set options = options|merge({'currentDepth': 0}) %} {% if options.style is defined and options.currentClass is defined and options.currentClass == 'current' %} {% set options = options|merge({'currentClass': 'active'}) %} {% set options = options|merge({'ancestorClass': 'active'}) %} {% endif %} {% set listAttributes = item.childrenAttributes %} {{ block('list') -}} {% endblock %} {% block list %} {% if item.hasChildren and options.depth is not same as (0) and item.displayChildren %} {# Il y a des items #} {% set listAttributes = listAttributes|merge({'class': listAttributes.class|default('')|trim}) %} {% set listClass = '' %} {# Type de menu #} {% if options.style is defined %} {% if options.style == 'horizontal' %} {% set listClass = 'navbar-nav' %} {% elseif options.style == 'horizontal-center' %} {% set listClass = 'navbar-nav justify-content-center' %} {% elseif options.style == 'horizontal-right' %} {% set listClass = 'navbar-nav ms-auto' %} {% elseif options.style == 'vertical' %} {% set listClass = 'flex-column' %} {% elseif options.style == 'vertical-pills' %} {% set listClass = 'flex-column nav-pills' %} {% elseif options.style == 'tabs' %} {% set listClass = 'nav-tabs' %} {% elseif options.style == 'pills' %} {% set listClass = 'nav-pills' %} {% elseif options.style == 'pills-fill' %} {% set listClass = 'nav-pills nav-fill' %} {% elseif options.style == 'pills-justify' %} {% set listClass = 'nav-pills nav-justified' %} {% endif %} {% endif %} {% set listClass = listClass ~ ' nav' %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' ' ~ listClass)|trim}) %} {{ block('children') }} {% endif %} {% endblock %} {% block listList %} {% apply spaceless %} {% if item.hasChildren and options.depth is not same as (0) and item.displayChildren %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' dropdown-menu')|trim}) %} {{ block('children') }} {% endif %} {% endapply %} {% endblock listList %} {% block collapseList %} {% apply spaceless %} {% if item.hasChildren and options.depth is not same as (0) and ((item.extras.dropdown is not defined and item.displayChildren is same as (true) or item.extras.dropdown is defined and item.extras.dropdown is same as (true) and item.displayChildren is same as (true))) %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' collapse sub-nav')|trim}) %} {% if (matcher is defined and matcher.isAncestor(item, options.depth)) or (item.currentAncestor is defined and item.currentAncestor) %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' show')|trim}) %} {% endif %} {{ block('children') }} {% endif %} {% endapply %} {% endblock %} {% block dropdownList %} {% apply spaceless %} {% if item.hasChildren and options.depth is not same as (0) and ((item.extras.dropdown is not defined and item.displayChildren is same as (true) or item.extras.dropdown is defined and item.extras.dropdown is same as (true) and item.displayChildren is same as (true))) %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' dropdown-menu')|trim}) %} {% if options.style in ['horizontal-right'] %} {% set listAttributes = listAttributes|merge({'class': (listAttributes.class|default('') ~ ' dropdown-menu dropdown-menu-end')|trim}) %} {% endif %} {{ block('children') }} {% endif %} {% endapply %} {% endblock dropdownList %} {% block children %} {# save current variables #} {% set currentOptions = options %} {% set currentItem = item %} {# update the depth for children #} {% if options.depth is not none %} {% set options = currentOptions|merge({'depth': currentOptions.depth - 1}) %} {% endif %} {% set options = options|merge({'currentDepth': options.currentDepth + 1}) %} {% for item in currentItem.children %} {{ block('item') }} {% endfor %} {# restore current variables #} {% set item = currentItem %} {% set options = currentOptions %} {% endblock %} {% block item %} {% if item.displayed %} {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %} {%- if (matcher is defined and matcher.isCurrent(item)) or (item.current is defined and item.current) %} {%- set classes = classes|merge([options.currentClass]) %} {%- elseif (matcher is defined and matcher.isAncestor(item, options.depth)) or (item.currentAncestor is defined and item.currentAncestor) %} {%- set classes = classes|merge([options.ancestorClass]) %} {%- endif %} {%- if item.actsLikeFirst %} {%- set classes = classes|merge([options.firstClass]) %} {%- endif %} {%- if item.actsLikeLast %} {%- set classes = classes|merge([options.lastClass]) %} {%- endif %} {%- if item.hasChildren and ((options.style is defined and options.style == 'list') or options.currentDepth is not same as (1)) %} {%- set classes = classes|merge(['dropdown-submenu']) %} {%- elseif item.hasChildren and options.style is defined and options.style in ['horizontal', 'horizontal-center', 'horizontal-right'] and ((item.extras.dropdown is not defined and item.displayChildren is same as (true) or item.extras.dropdown is defined and item.extras.dropdown is same as (true) and item.displayChildren is same as (true))) %} {%- set classes = classes|merge(['dropdown']) %} {%- endif %} {% if options.currentDepth == 1 or options.style in ['vertical', 'vertical-pills'] %} {%- set classes = classes|merge(['nav-item']) %} {% endif %} {%- set attributes = item.attributes %} {%- if classes is not empty %} {%- set attributes = attributes|merge({'class': classes|join(' ')}) %} {%- endif %} {% if item.hasChildren and options.style is defined and options.style in ['vertical', 'vertical-pills'] %} {{ block('collapseElement')}} {% elseif item.hasChildren and options.style is defined and options.style in ['horizontal', 'horizontal-center', 'horizontal-right'] %} {{ block('dropdownElement')}} {% elseif item.uri is not empty and ((item.current is defined and not item.current) or options.currentAsLink) %} {{ block('linkElement') }} {% endif %} {# Sous menu #} {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %} {%- set childrenClasses = childrenClasses|merge(['list-unstyled menu_level_' ~ item.level]) %} {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %} {%- set listAttributes = listAttributes|merge({'id': item.name|slugify }) %} {%- if item.hasChildren and options.style is defined and (options.style == 'list' or options.currentDepth is not same as (1)) %} {{ block('listList') }} {%- elseif item.hasChildren and options.style is defined and options.style in ['vertical', 'vertical-pills'] %} {{ block('collapseList') }} {%- elseif item.hasChildren and options.style is defined and options.style in ['horizontal', 'horizontal-center', 'horizontal-right'] %} {{ block('dropdownList') }} {%- else %} {{ block('list') }} {%- endif %} {% endif %} {% endblock %} {% block linkElement %} {% if options.currentDepth > 1 and options.style in ['horizontal', 'horizontal-center', 'horizontal-right'] %} {% set linkAttributes = item.linkAttributes|merge({'class': (linkAttributes.class|default('') ~ ' dropdown-item')}) %} {% else %} {% set linkAttributes = item.linkAttributes|merge({'class': (linkAttributes.class|default('') ~ ' nav-link')}) %} {% endif %} {%- if (matcher is defined and matcher.isCurrent(item)) or (item.current is defined and item.current) %} {% set linkAttributes = item.linkAttributes|merge({'class': (linkAttributes.class|default('') ~ ' ' ~ options.currentClass)}) %} {% endif %} {{ block('label') }} {% endblock %} {% block collapseElement %} {% apply spaceless %} {% set labelAttributes = item.labelAttributes %} {% if options.currentDepth > 1 %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' dropdown-item')|trim}) %} {% else %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' nav-link')|trim}) %} {% endif %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' dropdown-toggle collapsed')|trim}) %} {% set labelAttributes = labelAttributes|merge({'data-bs-toggle': 'collapse'}) %} {{ block('label') }} {% endapply %} {% endblock %} {% block dropdownElement %} {% apply spaceless %} {% set labelAttributes = item.labelAttributes %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' dropdown-toggle collapsed')|trim}) %} {% set labelAttributes = labelAttributes|merge({'data-bs-toggle': 'dropdown'}) %} {% set labelAttributes = labelAttributes|merge({'data-bs-target': '#' ~ (item.name|slugify) }) %} {% if options.currentDepth > 1 %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' dropdown-item')|trim}) %} {% else %} {% set labelAttributes = labelAttributes|merge({'class': (labelAttributes.class|default('') ~ ' nav-link')|trim}) %} {% endif %} {{ block('label') }} {% endapply %} {% endblock dropdownElement %} {% block label %} {%- set translation_domain = item.extra('translation_domain', 'messages') -%} {%- set label = item.label -%} {%- if translation_domain is not same as(false) -%} {%- set label = label|trans(item.extra('translation_params', {}), translation_domain) -%} {%- endif -%} {%- if options.allow_safe_labels and item.getExtra('safe_label', false) -%} {{ label|raw|parse_icons }} {%- else -%} {{ label|parse_icons }} {%- endif -%} {% endblock %}