Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / themes / classy / templates / navigation / menu.html.twig
1 {#
2 /**
3  * @file
4  * Theme override to display a menu.
5  *
6  * Available variables:
7  * - menu_name: The machine name of the menu.
8  * - items: A nested list of menu items. Each menu item contains:
9  *   - attributes: HTML attributes for the menu item.
10  *   - below: The menu item child items.
11  *   - title: The menu link title.
12  *   - url: The menu link url, instance of \Drupal\Core\Url
13  *   - localized_options: Menu link localized options.
14  *   - is_expanded: TRUE if the link has visible children within the current
15  *     menu tree.
16  *   - is_collapsed: TRUE if the link has children within the current menu tree
17  *     that are not currently visible.
18  *   - in_active_trail: TRUE if the link is in the active trail.
19  */
20 #}
21 {% import _self as menus %}
22
23 {#
24   We call a macro which calls itself to render the full tree.
25   @see http://twig.sensiolabs.org/doc/tags/macro.html
26 #}
27 {{ menus.menu_links(items, attributes, 0) }}
28
29 {% macro menu_links(items, attributes, menu_level) %}
30   {% import _self as menus %}
31   {% if items %}
32     {% if menu_level == 0 %}
33       <ul{{ attributes.addClass('menu') }}>
34     {% else %}
35       <ul class="menu">
36     {% endif %}
37     {% for item in items %}
38       {%
39         set classes = [
40           'menu-item',
41           item.is_expanded ? 'menu-item--expanded',
42           item.is_collapsed ? 'menu-item--collapsed',
43           item.in_active_trail ? 'menu-item--active-trail',
44         ]
45       %}
46       <li{{ item.attributes.addClass(classes) }}>
47         {{ link(item.title, item.url) }}
48         {% if item.below %}
49           {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
50         {% endif %}
51       </li>
52     {% endfor %}
53     </ul>
54   {% endif %}
55 {% endmacro %}