summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Carver2018-12-05 21:04:14 (GMT)
committerMark Carver2018-12-05 21:04:14 (GMT)
commit7adbbd14599137e5929449aeb7658341ce9421a5 (patch)
treea3b358a7d11bed3d8a66d1fbdacdf2f1be594135
parent6f968b866d849fa6ea3ddc8a9ddd84b6aac55656 (diff)
Issue #3018064 by markcarver, tanasi, glynster: Unable to easily add "dropdown-menu-right" to menus
-rw-r--r--templates/menu/menu--account.html.twig8
-rw-r--r--templates/menu/menu--main.html.twig2
-rw-r--r--templates/menu/menu.html.twig10
3 files changed, 16 insertions, 4 deletions
diff --git a/templates/menu/menu--account.html.twig b/templates/menu/menu--account.html.twig
index 4d2fcaa..0636e29 100644
--- a/templates/menu/menu--account.html.twig
+++ b/templates/menu/menu--account.html.twig
@@ -4,6 +4,8 @@
* Default theme implementation to display a menu.
*
* Available variables:
+ * - classes: A list of classes to apply to the top level <ul> element.
+ * - dropdown_classes: A list of classes to apply to the dropdown <ul> element.
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
@@ -25,3 +27,9 @@
'navbar-right',
]
%}
+{%
+ set dropdown_classes = [
+ 'dropdown-menu',
+ 'dropdown-menu-right',
+]
+%}
diff --git a/templates/menu/menu--main.html.twig b/templates/menu/menu--main.html.twig
index b912d17..3454340 100644
--- a/templates/menu/menu--main.html.twig
+++ b/templates/menu/menu--main.html.twig
@@ -4,6 +4,8 @@
* Default theme implementation to display a menu.
*
* Available variables:
+ * - classes: A list of classes to apply to the top level <ul> element.
+ * - dropdown_classes: A list of classes to apply to the dropdown <ul> element.
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
diff --git a/templates/menu/menu.html.twig b/templates/menu/menu.html.twig
index 0b94a21..e4dc11d 100644
--- a/templates/menu/menu.html.twig
+++ b/templates/menu/menu.html.twig
@@ -4,6 +4,8 @@
* Default theme implementation to display a menu.
*
* Available variables:
+ * - classes: A list of classes to apply to the top level <ul> element.
+ * - dropdown_classes: A list of classes to apply to the dropdown <ul> element.
* - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item.
@@ -17,9 +19,9 @@
* Define a custom macro that will render all menu trees.
*/
#}
-{% macro menu_links(items, attributes, menu_level, classes) %}
+{% macro menu_links(items, attributes, menu_level, classes, dropdown_classes) %}
{% if items %}
- <ul{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}>
+ <ul{{ attributes.addClass(menu_level == 0 ? classes : dropdown_classes) }}>
{% for item in items %}
{%
set item_classes = item.url.getOption('container_attributes').class | split(" ")
@@ -42,7 +44,7 @@
{# Must use link() here so it triggers hook_link_alter(). #}
{{ link(link_title, item.url, link_attributes.addClass(item.in_active_trail ? 'active-trail')) }}
{% if item.below %}
- {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes) }}
+ {{ _self.menu_links(item.below, attributes.removeClass(classes), menu_level + 1, classes, dropdown_classes) }}
{% endif %}
</li>
{% endfor %}
@@ -55,4 +57,4 @@
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']) }}
+{{ _self.menu_links(items, attributes, 0, classes ?: ['menu', 'menu--' ~ menu_name|clean_class, 'nav'], dropdown_classes ?: ['dropdown-menu']) }}