function _nodesymlinks_menu_get_active_trail in NodeSymlinks 6
Gets the active trail (path to root menu root) of the current page.
Return value
Path to menu root of the current page, as an array of menu link items, starting with the site's home page. Each link item is an associative array with the following components:
- title: Title of the item.
- href: Drupal path of the item.
- localized_options: Options for passing into the l() function.
- type: A menu type constant, such as MENU_DEFAULT_LOCAL_TASK, or 0 to indicate it's not really in the menu (used for the home page item).
If $new_trail is supplied, the value is saved in a static variable and returned. If $new_trail is not supplied, and there is a saved value from a previous call, the saved value is returned. If $new_trail is not supplied and there is no saved value, the path to the current page is calculated, saved as the static value, and returned.
See also
1 call to _nodesymlinks_menu_get_active_trail()
- nodesymlinks_get_breadcrumbs in ./
nodesymlinks.module - Generate breadcrumbs for current active menu trail. Return array of breadcrumb links. Partly taken from function menutrails_get_breadcrumbs().
File
- ./
nodesymlinks.module, line 181 - Node Symlinks allows creating duplicate menu links with unique id to all nodes. As a result all these duplicates have unique menu trails and breadcrumbs.
Code
function _nodesymlinks_menu_get_active_trail() {
static $trail;
if (!isset($trail)) {
$trail = array();
$item = menu_get_item();
$tree = menu_tree_page_data(menu_get_active_menu_name());
list($key, $curr) = each($tree);
while ($curr) {
// Terminate the loop when we find the current path in the active trail.
if ($curr['link']['href'] == $item['href']) {
$trail[] = $curr['link'];
$curr = FALSE;
}
else {
// Add the link if it's in the active trail, then move to the link
// below.
if ($curr['link']['in_active_trail']) {
$trail[] = $curr['link'];
$tree = $curr['below'] ? $curr['below'] : array();
}
list($key, $curr) = each($tree);
}
}
// Make sure the current page is in the trail (needed for the page title),
// but exclude tabs and the front page.
$last = count($trail) - 1;
if ($trail[$last]['href'] != $item['href'] && !(bool) ($item['type'] & MENU_IS_LOCAL_TASK) && !drupal_is_front_page()) {
$trail[] = $item;
}
}
return $trail;
}