Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / themes / contrib / bootstrap / templates / menu / menu.html.twig
index cbc5be86a5b683a0841f5784625fd0149b3f11fa..1f48ae6638d2939864538f15ac8284b0d246862d 100644 (file)
  *   - localized_options: Menu link localized options.
  *
  * @ingroup templates
+ *
+ * Define a custom macro that will render all menu trees.
  */
 #}
-{% import _self as menus %}
-
-{#
-  We call a macro which calls itself to render the full tree.
-  @see http://twig.sensiolabs.org/doc/tags/macro.html
-#}
-{{ menus.menu_links(items, attributes, 0) }}
-
-{% macro menu_links(items, attributes, menu_level) %}
-  {% import _self as menus %}
+{% macro menu_links(items, attributes, menu_level, classes) %}
   {% if items %}
-    {% if menu_level == 0 %}
-      <ul{{ attributes.addClass('menu', 'nav') }}>
-    {% else %}
-      <ul{{ attributes.addClass('dropdown-menu') }}>
-    {% endif %}
+    <ul{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}>
     {% for item in items %}
       {%
         set item_classes = [
-          item.is_expanded? 'expanded',
-          item.is_expanded and menu_level == 0 ? 'dropdown',
+          item.is_expanded and item.below ? 'expanded',
+          item.is_expanded and menu_level == 0 and item.below ? 'dropdown',
           item.in_active_trail ? 'active',
         ]
       %}
-      {% if menu_level == 0 and item.is_expanded %}
+      {% if menu_level == 0 and item.is_expanded and item.below %}
         <li{{ item.attributes.addClass(item_classes) }}>
-        <a href="{{ item.url }}" class="dropdown-toggle" data-target="#" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
+        <a href="{{ item.url }}" class="dropdown-toggle" data-toggle="dropdown">{{ item.title }} <span class="caret"></span></a>
       {% else %}
         <li{{ item.attributes.addClass(item_classes) }}>
         {{ link(item.title, item.url) }}
       {% endif %}
       {% if item.below %}
-        {{ menus.menu_links(item.below, attributes.removeClass('nav'), menu_level + 1) }}
+        {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
       {% endif %}
       </li>
     {% endfor %}
     </ul>
   {% endif %}
 {% endmacro %}
+
+{#
+  Invoke the custom macro defined above. If classes were provided, use them.
+  This allows the template to be extended without having to also duplicate the
+  code above. @see http://twig.sensiolabs.org/doc/tags/macro.html
+#}
+{{ _self.menu_links(items, attributes, 0, classes ? classes : ['menu', 'menu--' ~ menu_name|clean_class, 'nav']) }}