Commit af036d8c authored by Riccardo Padovani's avatar Riccardo Padovani

Added breadcrumb and third level menu

parent 56832962
......@@ -169,6 +169,8 @@ function valencia_links__system_main_menu($vars) {
return valencia_header_menu($vars);
case 'subheader':
return valencia_subheader_menu($vars);
case 'breadcrumb':
return valencia_breadcrumb($vars);
case 'footer':
return valencia_footer_menu($vars);
}
......@@ -226,6 +228,116 @@ function valencia_subheader_menu($vars) {
return $html;
}
/**
* Custom breadcrumb and third level menu
* Follows partially http://design.ubuntu.com/web-style-guide/scaffolding#navigation
*
* Breadcrumb is printed only on page with deep level > 1
* Also, if there is, we print third level menu
*/
function valencia_breadcrumb($vars) {
// Var with all HTML
$html = '';
foreach ($vars['links'] as $key => $link) {
// See Drupal API, is to print every menu voice only one
if (is_numeric($key)) {
// We need only active links
if ($link['#original_link']['in_active_trail']) {
// If is the first level link and it has children, we have our first
// link of breadcrumb!
if(!empty($link['#below']) && $link['#original_link']['depth'] === '1') {
$link_title = $link['#title'];
$link_href = $link['#href'];
$html .= '<ul class="breadcrumb">';
$html .= '<li>' . l($link_title, $link_href, array('html' => 'true')) . '&nbsp;&rsaquo;</li>';
// Now we need to attach second level menu
$sub_menu = theme('links__system_main_menu', array(
'links' => $link['#below'],
'id' => 'breadcrumb'
));
$html .= $sub_menu;
}
// Second level link: could be the active one, or only a
// breadcrumb for third level (or both)
else if ($link['#original_link']['depth'] === '2') {
// If it hasn't child, is the active link
if (empty($link['#below'])) {
$link_title = $link['#title'];
$link_href = $link['#href'];
$html .= '<li class="active">' . l($link_title, $link_href, array('html' => 'true')) . '</li>';
// We close the ul with class breadcrumb, as per design
$html .= '</ul>';
}
else {
// If it has children could be active or not.
// To check we need to create first the third level
// menu, and check if any of the third level menu links
// is active
list ($has_child_active_link, $third_level_menu) = valencia_third_level_menu($link['#below']);
$link_title = $link['#title'];
$link_href = $link['#href'];
// If a child is active, this one isn't active
if ($has_child_active_link) {
$html .= '<li>' . l($link_title, $link_href, array('html' => 'true')) . '&nbsp;&rsaquo;</li>';
}
else {
$html .= '<li class="active">' . l($link_title, $link_href, array('html' => 'true')) . '</li>';
}
// We close the ul with class breadcrumb, as per design
$html .= '</ul>';
// Then, third level menu
$html .= $third_level_menu;
}
}
}
}
}
return $html;
}
/**
* Create third level menu html
* Follows http://design.ubuntu.com/web-style-guide/scaffolding#navigation
*
* Don't call this function directly, is only for valencia_breadcrumb()
*
* Return an array: the first element is a bool that indicate if there is an
* active link, the second element is the html of third level menu
*/
function valencia_third_level_menu($vars) {
// Var with all HTML
$html = '<ul class="third-level">';
// This becomes TRUE if there is an active link
$has_active_link = FALSE;
foreach ($vars as $key => $link) {
// See Drupal API, is to print every menu voice only one
if (is_numeric($key)) {
if ($link['#original_link']['in_active_trail']) {
$has_active_link = TRUE;
$link_title = $link['#title'];
$link_href = $link['#href'];
$html .= '<li class="active">' . l($link_title, $link_href, array('html' => 'true')) . '</li>';
}
else {
$link_title = $link['#title'];
$link_href = $link['#href'];
$html .= '<li>' . l($link_title, $link_href, array('html' => 'true')) . '</li>';
}
}
}
$html .= '</ul>';
return array($has_active_link, $html);
}
/**
* Custom links for footer menu
* Follows http://design.ubuntu.com/web-style-guide/scaffolding#footer
......
......@@ -111,13 +111,20 @@
</nav>
</header>
<div class="wrapper"><div id="page">
<div class="wrapper">
<div id="main-content" class="inner-wrapper">
<?php if ($breadcrumb): ?>
<div id="breadcrumb"><?php print $breadcrumb; ?></div>
<?php endif; ?>
<?php print $messages; // Error messages ?>
<?php if ($breadcrumb): ?>
<nav role="navigation" class="nav-secondary clearfix">
<?php print theme('links__system_main_menu', array(
'links' => $valencia_menu,
'id' => 'breadcrumb'
));?>
</nav>
<?php endif; ?>
<?php print $messages; ?>
<div id="main-wrapper"><div id="main" class="clearfix">
......@@ -134,7 +141,7 @@
</div></div> <!-- /#main, /#main-wrapper -->
</div></div> <!-- /#page, /.wrapper -->
</div></div> <!-- /#main-content, /.wrapper -->
<footer class="global clearfix">
<nav role="navigation">
......
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