function menutrails_primary_links in Menu TrailsMenu Trails 5
This is a substitute function for menu_primary_links()
The important difference is a different criteria for determining if an item is "active" or not, and the use of our own _menu_item() function to make use of that active status.
File
- ./
menutrails.module, line 191 - Menutrails allows the assigment of "trails" which will keep menu items active for individual node views.
Code
function menutrails_primary_links($start_level = 1, $pid = 0) {
if (!module_exists('menu')) {
return NULL;
}
if (!$pid) {
$pid = variable_get('menu_primary_menu', 0);
}
if (!$pid) {
return NULL;
}
if ($start_level < 1) {
$start_level = 1;
}
if ($start_level > 1) {
$trail = _menu_get_active_trail_in_submenu($pid);
if (!$trail) {
return NULL;
}
else {
$pid = $trail[$start_level - 1];
}
}
$menu = menu_get_menu();
$links = array();
// Custom data for use down the line
$trail = _menu_get_active_trail();
if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
$count = 1;
foreach ($menu['visible'][$pid]['children'] as $cid) {
$index = "menu-{$start_level}-{$count}-{$pid}";
// this needs to be unset
unset($active);
// changed from menu_in_active_subtrail
if (in_array($cid, $trail)) {
$index .= "-active";
// we use this below
$active = TRUE;
}
// use $active
$links[$index] = menutrails_item_link($cid, FALSE, $active);
$count++;
}
}
// Special case - provide link to admin/build/menu if primary links is empty.
if (empty($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0) && user_access('administer menu')) {
$links['1-1'] = array(
'title' => t('Edit primary links'),
'href' => 'admin/build/menu',
);
}
return $links;
}