Commit 7adbbd14 authored by markcarver's avatar markcarver

Issue #3018064 by markcarver, tanasi, glynster: Unable to easily add "dropdown-menu-right" to menus

parent 6f968b86
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* Default theme implementation to display a menu. * Default theme implementation to display a menu.
* *
* Available variables: * 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. * - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains: * - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item. * - attributes: HTML attributes for the menu item.
...@@ -25,3 +27,9 @@ ...@@ -25,3 +27,9 @@
'navbar-right', 'navbar-right',
] ]
%} %}
{%
set dropdown_classes = [
'dropdown-menu',
'dropdown-menu-right',
]
%}
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* Default theme implementation to display a menu. * Default theme implementation to display a menu.
* *
* Available variables: * 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. * - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains: * - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item. * - attributes: HTML attributes for the menu item.
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* Default theme implementation to display a menu. * Default theme implementation to display a menu.
* *
* Available variables: * 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. * - menu_name: The machine name of the menu.
* - items: A nested list of menu items. Each menu item contains: * - items: A nested list of menu items. Each menu item contains:
* - attributes: HTML attributes for the menu item. * - attributes: HTML attributes for the menu item.
...@@ -17,9 +19,9 @@ ...@@ -17,9 +19,9 @@
* Define a custom macro that will render all menu trees. * 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 %} {% if items %}
<ul{{ attributes.addClass(menu_level == 0 ? classes : 'dropdown-menu') }}> <ul{{ attributes.addClass(menu_level == 0 ? classes : dropdown_classes) }}>
{% for item in items %} {% for item in items %}
{% {%
set item_classes = item.url.getOption('container_attributes').class | split(" ") set item_classes = item.url.getOption('container_attributes').class | split(" ")
...@@ -42,7 +44,7 @@ ...@@ -42,7 +44,7 @@
{# Must use link() here so it triggers hook_link_alter(). #} {# Must use link() here so it triggers hook_link_alter(). #}
{{ link(link_title, item.url, link_attributes.addClass(item.in_active_trail ? 'active-trail')) }} {{ link(link_title, item.url, link_attributes.addClass(item.in_active_trail ? 'active-trail')) }}
{% if item.below %} {% 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 %} {% endif %}
</li> </li>
{% endfor %} {% endfor %}
...@@ -55,4 +57,4 @@ ...@@ -55,4 +57,4 @@
This allows the template to be extended without having to also duplicate the This allows the template to be extended without having to also duplicate the
code above. @see http://twig.sensiolabs.org/doc/tags/macro.html 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']) }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment