Skip to content

Instantly share code, notes, and snippets.

@johnny5th
Last active December 11, 2015 03:59
Show Gist options
  • Save johnny5th/4542035 to your computer and use it in GitHub Desktop.
Save johnny5th/4542035 to your computer and use it in GitHub Desktop.
Add a subnav to a Drupal theme from the secondary menu and include a "back" button if the active trail is in the sub nav.
<?php
function TEMPLATE_preprocess_page(&$variables, $hook) {
$variables['secondary_menu'] = menu_secondary_menu();
$activesub = false;
foreach($variables['secondary_menu'] as $item) {
if(isset($item['attributes']['class']))
foreach($item['attributes']['class'] as $class)
if($class == "active-trail")
$activesub = true;
}
$active_trail = menu_get_active_trail();
if(sizeof($active_trail) > 2) {
end($active_trail);
$parent = prev($active_trail);
array_unshift($variables['secondary_menu'], array('title' => '<<Back ', 'href' => $parent['href']));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment