Skip to content

Commit 479f8d3

Browse files
Stephen Mulvihillsylus
authored andcommitted
Issue #3310969 by smulvih2: Support horizontal main menu in GCWeb
1 parent 06a9303 commit 479f8d3

File tree

7 files changed

+184
-44
lines changed

7 files changed

+184
-44
lines changed

src/Plugin/Preprocess/Menu.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public function preprocess(array &$variables, $hook, array $info) {
8181
}
8282
}
8383

84+
// Determine menu orientation.
85+
$config = \Drupal::config('wxt_library.settings');
86+
$menu_type = $config->get('wxt.menu_type');
87+
if ($menu_type) {
88+
$variables['menu_type'] = 'horizontal';
89+
}
90+
else {
91+
$variables['menu_type'] = 'default';
92+
}
93+
8494
parent::preprocess($variables, $hook, $info);
8595
}
8696

src/Plugin/Preprocess/Region.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public function preprocessVariables(Variables $variables) {
3636
$variables->addClass(['pagedetails']);
3737
}
3838
}
39+
40+
if ($wxt_active == 'gcweb') {
41+
$config = \Drupal::config('wxt_library.settings');
42+
$menu_type = $config->get('wxt.menu_type');
43+
if ($region === 'search' && $menu_type) {
44+
$variables->addClass(['visible-md visible-lg']);
45+
}
46+
}
3947
}
4048

4149
}

templates/menu/menu--main--gcweb.html.twig

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,33 @@
2121
We call a macro which calls itself to render the full tree.
2222
@see http://twig.sensiolabs.org/doc/tags/macro.html
2323
#}
24-
{{ menus.menu_links(items, attributes, 0, menu_name|clean_class, gcweb_cdn, gcweb_cdn_url, language) }}
24+
{{ menus.menu_links(menu_type, items, attributes, 0, menu_name|clean_class, gcweb_cdn, gcweb_cdn_url, language) }}
2525

26-
{% macro menu_links(items, attributes, menu_level, menu_name, gcweb_cdn, gcweb_cdn_url, language) %}
26+
{% macro menu_links(menu_type, items, attributes, menu_level, menu_name, gcweb_cdn, gcweb_cdn_url, language) %}
2727
{% import _self as menus %}
2828
{% if items %}
2929
{% if menu_level == 0 %}
3030
{% if gcweb_cdn and gcweb_cdn_url %}
3131
<ul role="menu" aria-orientation="vertical" data-ajax-replace="{{ gcweb_cdn_url }}{{ language }}.html">
3232
{% else %}
33-
<ul role="menu" aria-orientation="vertical">
33+
{% if menu_type == 'default' %}
34+
<ul role="menu" aria-orientation="vertical">
35+
{% elseif menu_type == 'horizontal' %}
36+
<ul role="menubar"{{ attributes.addClass('list-inline', 'menu') }}>
37+
{% endif %}
3438
{% endif %}
3539
{% elseif menu_level == 1 %}
36-
<ul role="menu" aria-orientation="vertical"{{ attributes.removeClass('menu', 'list-inline') }}>
40+
{% if menu_type == 'default' %}
41+
<ul role="menu" aria-orientation="vertical"{{ attributes.removeClass('menu', 'list-inline') }}>
42+
{% elseif menu_type == 'horizontal' %}
43+
<ul role="menu"{{ attributes.addClass('sm', 'list-unstyled').removeClass('menu', 'list-inline') }} aria-expanded="false" aria-hidden="true">
44+
{% endif %}
3745
{% else %}
38-
<ul role="menu" aria-orientation="vertical">
46+
{% if menu_type == 'default' %}
47+
<ul role="menu" aria-orientation="vertical">
48+
{% elseif menu_type == 'horizontal' %}
49+
<ul role="menu"{{ attributes.addClass('dropdown-menu', menu_name) }}>
50+
{% endif %}
3951
{% endif %}
4052
{% for item in items %}
4153
{%
@@ -46,14 +58,24 @@
4658
]
4759
%}
4860
{% if menu_level == 0 and item.is_expanded %}
49-
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
50-
<a role="menuitem" href="{{ item.url }}" tabindex="-1" aria-haspopup="true" aria-controls="{{ item.title | clean_id }}" aria-expanded="false">{{ item.title }}</a>
61+
{% if menu_type == 'default' %}
62+
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
63+
<a role="menuitem" href="{{ item.url }}" tabindex="-1" aria-haspopup="true" aria-controls="{{ item.title | clean_id }}" aria-expanded="false">{{ item.title }}</a>
64+
{% elseif menu_type == 'horizontal' %}
65+
<li role="presentation"{{ item.attributes }}>
66+
<a role="menuitem" class="dropdown-toggle item" href="{{ item.url }}">{{ item.title }}</a>
67+
{% endif %}
5168
{% else %}
52-
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
53-
{{ link(item.title, item.url, {'role':['menuitem']}) }}
69+
{% if menu_type == 'default' %}
70+
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
71+
{{ link(item.title, item.url, {'role':['menuitem']}) }}
72+
{% elseif menu_type == 'horizontal' %}
73+
<li role="presentation"{{ item.attributes }}>
74+
{{ link(item.title, item.url, {'role':['menuitem']}) }}
75+
{% endif %}
5476
{% endif %}
5577
{% if item.below %}
56-
{{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
78+
{{ menus.menu_links(menu_type, item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
5779
{% endif %}
5880
</li>
5981
{% endfor %}

templates/menu/menu--main-fr--gcweb.html.twig

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,33 @@
2121
We call a macro which calls itself to render the full tree.
2222
@see http://twig.sensiolabs.org/doc/tags/macro.html
2323
#}
24-
{{ menus.menu_links(items, attributes, 0, menu_name|clean_class, gcweb_cdn, gcweb_cdn_url, language) }}
24+
{{ menus.menu_links(menu_type, items, attributes, 0, menu_name|clean_class, gcweb_cdn, gcweb_cdn_url, language) }}
2525

26-
{% macro menu_links(items, attributes, menu_level, menu_name, gcweb_cdn, gcweb_cdn_url, language) %}
26+
{% macro menu_links(menu_type, items, attributes, menu_level, menu_name, gcweb_cdn, gcweb_cdn_url, language) %}
2727
{% import _self as menus %}
2828
{% if items %}
2929
{% if menu_level == 0 %}
3030
{% if gcweb_cdn and gcweb_cdn_url %}
3131
<ul role="menu" aria-orientation="vertical" data-ajax-replace="{{ gcweb_cdn_url }}{{ language }}.html">
3232
{% else %}
33-
<ul role="menu" aria-orientation="vertical">
33+
{% if menu_type == 'default' %}
34+
<ul role="menu" aria-orientation="vertical">
35+
{% elseif menu_type == 'horizontal' %}
36+
<ul role="menubar"{{ attributes.addClass('list-inline', 'menu') }}>
37+
{% endif %}
3438
{% endif %}
3539
{% elseif menu_level == 1 %}
36-
<ul role="menu" aria-orientation="vertical"{{ attributes.removeClass('menu', 'list-inline') }}>
40+
{% if menu_type == 'default' %}
41+
<ul role="menu" aria-orientation="vertical"{{ attributes.removeClass('menu', 'list-inline') }}>
42+
{% elseif menu_type == 'horizontal' %}
43+
<ul role="menu"{{ attributes.addClass('sm', 'list-unstyled').removeClass('menu', 'list-inline') }} aria-expanded="false" aria-hidden="true">
44+
{% endif %}
3745
{% else %}
38-
<ul role="menu" aria-orientation="vertical">
46+
{% if menu_type == 'default' %}
47+
<ul role="menu" aria-orientation="vertical">
48+
{% elseif menu_type == 'horizontal' %}
49+
<ul role="menu"{{ attributes.addClass('dropdown-menu', menu_name) }}>
50+
{% endif %}
3951
{% endif %}
4052
{% for item in items %}
4153
{%
@@ -46,14 +58,24 @@
4658
]
4759
%}
4860
{% if menu_level == 0 and item.is_expanded %}
49-
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
50-
<a role="menuitem" href="{{ item.url }}" tabindex="-1" aria-haspopup="true" aria-controls="{{ item.title | clean_id }}" aria-expanded="false">{{ item.title }}</a>
61+
{% if menu_type == 'default' %}
62+
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
63+
<a role="menuitem" href="{{ item.url }}" tabindex="-1" aria-haspopup="true" aria-controls="{{ item.title | clean_id }}" aria-expanded="false">{{ item.title }}</a>
64+
{% elseif menu_type == 'horizontal' %}
65+
<li role="presentation"{{ item.attributes }}>
66+
<a role="menuitem" class="dropdown-toggle item" href="{{ item.url }}">{{ item.title }}</a>
67+
{% endif %}
5168
{% else %}
52-
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
53-
{{ link(item.title, item.url, {'role':['menuitem']}) }}
69+
{% if menu_type == 'default' %}
70+
<li role="presentation"{{ item.attributes.addClass(item_classes) }}>
71+
{{ link(item.title, item.url, {'role':['menuitem']}) }}
72+
{% elseif menu_type == 'horizontal' %}
73+
<li role="presentation"{{ item.attributes }}>
74+
{{ link(item.title, item.url, {'role':['menuitem']}) }}
75+
{% endif %}
5476
{% endif %}
5577
{% if item.below %}
56-
{{ menus.menu_links(item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
78+
{{ menus.menu_links(menu_type, item.below, attributes.removeClass('nav', 'navbar-nav'), menu_level + 1) }}
5779
{% endif %}
5880
</li>
5981
{% endfor %}

templates/page/page--gcweb--book-index.html.twig

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,47 @@
7272
<header{{ navbar_attributes.addClass(navbar_classes) }} id="navbar">
7373
<div id="wb-bnr" class="{{ container }}">
7474
<div class="row">
75-
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right">
75+
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right {{ menu_type == 'horizontal' ? 'visible-md visible-lg' : '' }}">
7676
<h2 class="wb-inv">{{ 'Language selection'|t }}</h2>
7777
{{ page.language_toggle }}
7878
</section>
7979
{{ page.banner }}
80+
{% if menu_type == 'horizontal' %}
81+
<section class="wb-mb-links col-xs-4 col-sm-3 visible-sm visible-xs pull-right" id="wb-glb-mn">
82+
<h2>{{ 'Search and menus'|t }}</h2>
83+
<ul class="list-inline text-right chvrn">
84+
<li>
85+
<a href="#mb-pnl" title="{{ 'Search and menus'|t }}" aria-controls="mb-pnl" class="overlay-lnk" role="button">
86+
<span class="glyphicon glyphicon-search">
87+
<span class="glyphicon glyphicon-th-list">
88+
<span class="wb-inv">{{ 'Search and menus'|t }}</span>
89+
</span>
90+
</span>
91+
</a>
92+
</li>
93+
</ul>
94+
<div id="mb-pnl"></div>
95+
</section>
96+
{% endif %}
8097
{{ page.search }}
8198
</div>
8299
</div>
83-
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
84-
<div class="{{ container }}">
85-
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
86-
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
87-
{{ page.navigation }}
88-
</div>
89-
</nav>
100+
{% if menu_type == 'default' %}
101+
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
102+
<div class="container">
103+
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
104+
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
105+
{{ page.navigation }}
106+
</div>
107+
</nav>
108+
{% elseif menu_type == 'horizontal' %}
109+
<nav aria-labelledby="topicsMenu" id="wb-sm" class="wb-menu visible-md visible-lg" data-trgt="mb-pnl">
110+
<div class="pnl-strt {{ container }} nvbar">
111+
<h2 id="topicsMenu" class="wb-inv">{{ 'Menu'|t }}</h2>
112+
{{ page.navigation }}
113+
</div>
114+
</nav>
115+
{% endif %}
90116
{{ page.breadcrumb }}
91117
</header>
92118
{% endblock %}

templates/page/page--gcweb--book-page.html.twig

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,47 @@
7272
<header{{ navbar_attributes.addClass(navbar_classes) }} id="navbar">
7373
<div id="wb-bnr" class="{{ container }}">
7474
<div class="row">
75-
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right">
75+
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right {{ menu_type == 'horizontal' ? 'visible-md visible-lg' : '' }}">
7676
<h2 class="wb-inv">{{ 'Language selection'|t }}</h2>
7777
{{ page.language_toggle }}
7878
</section>
7979
{{ page.banner }}
80+
{% if menu_type == 'horizontal' %}
81+
<section class="wb-mb-links col-xs-4 col-sm-3 visible-sm visible-xs pull-right" id="wb-glb-mn">
82+
<h2>{{ 'Search and menus'|t }}</h2>
83+
<ul class="list-inline text-right chvrn">
84+
<li>
85+
<a href="#mb-pnl" title="{{ 'Search and menus'|t }}" aria-controls="mb-pnl" class="overlay-lnk" role="button">
86+
<span class="glyphicon glyphicon-search">
87+
<span class="glyphicon glyphicon-th-list">
88+
<span class="wb-inv">{{ 'Search and menus'|t }}</span>
89+
</span>
90+
</span>
91+
</a>
92+
</li>
93+
</ul>
94+
<div id="mb-pnl"></div>
95+
</section>
96+
{% endif %}
8097
{{ page.search }}
8198
</div>
8299
</div>
83-
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
84-
<div class="{{ container }}">
85-
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
86-
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
87-
{{ page.navigation }}
88-
</div>
89-
</nav>
100+
{% if menu_type == 'default' %}
101+
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
102+
<div class="container">
103+
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
104+
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
105+
{{ page.navigation }}
106+
</div>
107+
</nav>
108+
{% elseif menu_type == 'horizontal' %}
109+
<nav aria-labelledby="topicsMenu" id="wb-sm" class="wb-menu visible-md visible-lg" data-trgt="mb-pnl">
110+
<div class="pnl-strt {{ container }} nvbar">
111+
<h2 id="topicsMenu" class="wb-inv">{{ 'Menu'|t }}</h2>
112+
{{ page.navigation }}
113+
</div>
114+
</nav>
115+
{% endif %}
90116
{{ page.breadcrumb }}
91117
</header>
92118
{% endblock %}

templates/page/page--gcweb.html.twig

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,47 @@
7272
<header{{ navbar_attributes.addClass(navbar_classes) }} id="navbar">
7373
<div id="wb-bnr" class="container">
7474
<div class="row">
75-
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right">
75+
<section id="wb-lng" class="col-xs-3 col-sm-12 pull-right text-right {{ menu_type == 'horizontal' ? 'visible-md visible-lg' : '' }}">
7676
<h2 class="wb-inv">{{ 'Language selection'|t }}</h2>
7777
{{ page.language_toggle }}
7878
</section>
7979
{{ page.banner }}
80+
{% if menu_type == 'horizontal' %}
81+
<section class="wb-mb-links col-xs-4 col-sm-3 visible-sm visible-xs pull-right" id="wb-glb-mn">
82+
<h2>{{ 'Search and menus'|t }}</h2>
83+
<ul class="list-inline text-right chvrn">
84+
<li>
85+
<a href="#mb-pnl" title="{{ 'Search and menus'|t }}" aria-controls="mb-pnl" class="overlay-lnk" role="button">
86+
<span class="glyphicon glyphicon-search">
87+
<span class="glyphicon glyphicon-th-list">
88+
<span class="wb-inv">{{ 'Search and menus'|t }}</span>
89+
</span>
90+
</span>
91+
</a>
92+
</li>
93+
</ul>
94+
<div id="mb-pnl"></div>
95+
</section>
96+
{% endif %}
8097
{{ page.search }}
8198
</div>
8299
</div>
83-
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
84-
<div class="container">
85-
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
86-
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
87-
{{ page.navigation }}
88-
</div>
89-
</nav>
100+
{% if menu_type == 'default' %}
101+
<nav class="gcweb-menu" data-trgt="mb-pnl" typeof="SiteNavigationElement">
102+
<div class="container">
103+
<h2 class="wb-inv">{{ 'Menu'|t }}</h2>
104+
<button type="button" aria-haspopup="true" aria-expanded="false">{{ main_menu_label|raw }}</button>
105+
{{ page.navigation }}
106+
</div>
107+
</nav>
108+
{% elseif menu_type == 'horizontal' %}
109+
<nav aria-labelledby="topicsMenu" id="wb-sm" class="wb-menu visible-md visible-lg" data-trgt="mb-pnl">
110+
<div class="pnl-strt {{ container }} nvbar">
111+
<h2 id="topicsMenu" class="wb-inv">{{ 'Menu'|t }}</h2>
112+
{{ page.navigation }}
113+
</div>
114+
</nav>
115+
{% endif %}
90116
{{ page.breadcrumb }}
91117
</header>
92118
{% endblock %}

0 commit comments

Comments
 (0)