Skip to content
Snippets Groups Projects
menu.twig 4.48 KiB
{% import _self as menus %}

{% set menu_parent_hide = false %}

{{ menus.menu_links(items, attributes, 0, menu_name, menu_class, item_class, link_class) }}

{% macro menu_links(items, attributes, menu_level, menu_name, menu_class, item_class, link_class, parent) %}

  {% import _self as menus %}

  {% if items %}

    {% if menu_level == 0 %}

      {# double quotes around class using menu_name needed for interpolation #}
      {% set additional_classes = [
        'menu',
        "menu--#{menu_name}"
      ] %}

      {% if menu_class %}
        {% set additional_classes = additional_classes|merge(menu_class) %}
      {% endif %}

      {% set additional_attributes = {
        'class': additional_classes
      } %}
      <ul {{ add_attributes(additional_attributes) }}>

    {% else %}
      <ul class="menu menu--subnav">
    {% endif %}

    {% for item in items %}

      {% set item_classes = ['menu--item'] %}
      {% set link_classes = ['menu--link'] %}

      {% if item.active_trail %}
        {% set item_classes = item_classes|merge(['is-active-trail']) %}
      {% endif %}

      {% if item.active %}
        {% set link_classes = link_classes|merge(['active']) %}
      {% endif %}

      {% if item_class %}
        {% set item_classes = item_classes|merge(item_class) %}
      {% endif %}

      {% if link_class %}
        {% set link_classes = link_classes|merge(link_class) %}
      {% endif %}

      {# Check for submenu  #}
      {% if item.submenu %}

        {# Add class for indicating the item has a submenu  #}
        {% set item_classes = item_classes|merge(['has-submenu']) %}

        {# Check if we are in parent menu_level #}
        {% if menu_level == 0 %}

          {# Look to see if the menu_items_count is set so and use for menu dropdown class  #}
          {% if item.menu_items_count %}

            {% if item.menu_items_count >= 30 %}

              {% set item_classes = item_classes|merge(['has-submenu--large']) %}