Newer
Older
Brian Canini
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{#
/**
* @file
* Default theme implementation to display a book tree.
*
* Returns HTML for a wrapper for a book sub-tree.
*
* Available variables:
* - items: A nested list of book items. Each book item contains:
* - attributes: HTML attributes for the book item.
* - below: The book item child items.
* - title: The book link title.
* - url: The book link URL, instance of \Drupal\Core\Url.
* - is_expanded: TRUE if the link has visible children within the current
* book tree.
* - is_collapsed: TRUE if the link has children within the current book tree
* that are not currently visible.
* - in_active_trail: TRUE if the link is in the active trail.
*
* @ingroup themeable
*/
#}
{% import _self as book_tree %}
{#
We call a macro which calls itself to render the full tree.
@see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ book_tree.book_links(items, attributes, 0) }}
{% macro book_links(items, attributes, menu_level) %}
{% import _self as book_tree %}
{% if items %}
{% if menu_level == 0 %}
<ul{{ attributes }} class="book-nav">
{% else %}
<ul>
{% endif %}
{% for item in items %}
{%
set item_classes = item.url.getOption('container_attributes').class | split(" ")
%}
{%
set item_classes = [
item.is_expanded and item.below ? 'expanded dropdown',
item.in_active_trail ? 'active active-trail',
loop.first ? 'first',
loop.last ? 'last',
]
%}
<li{{ item.attributes.addClass(item_classes) }}>
{% set link_title = item.title %}
{% set link_attributes = item.link_attributes %}
{% if item.is_expanded and item.below %}
<div class="link-wrapper">{{ link(link_title, item.url, link_attributes.addClass(item.in_active_trail ? 'active-trail')) }} <i class="fa fa-angle-down" aria-hidden="true"></i></div>
{% else %}
<div class="link-wrapper">{{ link(link_title, item.url, link_attributes.addClass(item.in_active_trail ? 'active-trail')) }}</div>
{% endif %}
{% if item.below %}
{{ book_tree.book_links(item.below, attributes.removeClass(classes), menu_level + 1, dropdown_classes) }}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}