Commit 56832962 authored by Riccardo Padovani's avatar Riccardo Padovani

Create function to generate subheader

parent 8e3dc772
...@@ -116,11 +116,50 @@ function valencia_preprocess_html( &$variables ) { ...@@ -116,11 +116,50 @@ function valencia_preprocess_html( &$variables ) {
function valencia_preprocess_page( &$vars ) { function valencia_preprocess_page( &$vars ) {
// Get the entire main menu tree // Get the entire main menu tree
$main_menu_tree = menu_tree_all_data('main-menu'); $main_menu_tree = menu_tree_all_data('main-menu');
// and add the active trail
menu_tree_add_active_path($main_menu_tree);
// Add the rendered output to menu // Add the rendered output to menu
$vars['valencia_menu'] = menu_tree_output($main_menu_tree); $vars['valencia_menu'] = menu_tree_output($main_menu_tree);
} }
/**
* Add the active trail indicators into the tree.
*
* The data returned by menu_tree_page_data() has link['in_active_trail'] set
* to TRUE for each menu item in the active trail. The data returned from
* menu_tree_all_data() does not contain the active trail indicators. This is a
* helper function that adds it back in.
*
* Source:
* http://drupalcontrib.org/api/drupal/contributions!menu_block!menu_block.module/function/menu_tree_add_active_path/7
*/
function menu_tree_add_active_path(&$tree) {
// Grab any menu item to find the menu_name for this tree.
$menu_item = current($tree);
$tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name']);
// To traverse the original tree down the active trail, we use a pointer.
$subtree_pointer = &$tree;
// Find each key in the active trail.
while ($tree_with_trail) {
foreach ($tree_with_trail as $key => &$value) {
if ($tree_with_trail[$key]['link']['in_active_trail']) {
// Set the active trail info in the original tree.
$subtree_pointer[$key]['link']['in_active_trail'] = TRUE;
// Continue in the subtree, if it exists.
$tree_with_trail = &$tree_with_trail[$key]['below'];
$subtree_pointer = &$subtree_pointer[$key]['below'];
break;
}
else {
unset($tree_with_trail[$key]);
}
}
}
}
/** /**
* Choose which menu create basing on the id * Choose which menu create basing on the id
*/ */
...@@ -128,6 +167,8 @@ function valencia_links__system_main_menu($vars) { ...@@ -128,6 +167,8 @@ function valencia_links__system_main_menu($vars) {
switch ($vars['id']) { switch ($vars['id']) {
case 'header': case 'header':
return valencia_header_menu($vars); return valencia_header_menu($vars);
case 'subheader':
return valencia_subheader_menu($vars);
case 'footer': case 'footer':
return valencia_footer_menu($vars); return valencia_footer_menu($vars);
} }
...@@ -154,6 +195,37 @@ function valencia_header_menu($vars) { ...@@ -154,6 +195,37 @@ function valencia_header_menu($vars) {
return $html; return $html;
} }
/**
* Custom links for subheader menu
* Follows a custom design
*
* We need to print only the submenu of active menu
*/
function valencia_subheader_menu($vars) {
// Var with all HTML of the menu
$html = '<ul>';
foreach ($vars['links'] as $key => $link) {
// To print every menu voice only one, see Drupal API
if (is_numeric($key)) {
// Check for submenu, but only if they are of first level and this
// is the active link
if (!empty($link['#below']) && $link['#original_link']['depth'] === '1' && $link['#original_link']['in_active_trail']) {
// If there is a submenu create it using the header function,
// because they have the same struct
$sub_menu = theme('links__system_main_menu', array(
'links' => $link['#below'],
'id' => 'header'
));
$html .= $sub_menu;
}
}
}
$html .= '</ul>';
return $html;
}
/** /**
* Custom links for footer menu * Custom links for footer menu
* Follows http://design.ubuntu.com/web-style-guide/scaffolding#footer * Follows http://design.ubuntu.com/web-style-guide/scaffolding#footer
......
...@@ -98,9 +98,10 @@ ...@@ -98,9 +98,10 @@
</header> </header>
<header class="banner global inverted" role="banner"> <header class="banner global inverted" role="banner">
<nav class="nav-primary nav-left" role="navigation"> <nav class="nav-primary nav-left" role="navigation">
<ul> <?php print theme('links__system_main_menu', array(
<li><a href="#">Somewhere</a></li> 'links' => $valencia_menu,
</ul> 'id' => 'subheader'
));?>
<form action="/search" id="search-form" class="header-search"> <form action="/search" id="search-form" class="header-search">
<input type="search" maxlength="255" name="q" id="edit-keys" class="form-text" placeholder="Cerca&hellip;" value="" /> <input type="search" maxlength="255" name="q" id="edit-keys" class="form-text" placeholder="Cerca&hellip;" value="" />
<button type="submit"> <button type="submit">
......
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