function menu_primary_links in Drupal 4
Same name and namespace in other branches
- 5 includes/menu.inc \menu_primary_links()
- 6 includes/menu.inc \menu_primary_links()
Returns an array containing the primary links. Can optionally descend from the root of the Primary links menu towards the current node for a specified number of levels and return that submenu. Used to generate a primary/secondary menu from different levels of one menu.
Parameters
$start_level: This optional parameter can be used to retrieve a context-sensitive array of links at $start_level levels deep into the Primary links menu. The default is to return the top-level links.
$pid: The parent menu ID from which to search for children. Defaults to the menu_primary_menu setting.
Return value
An array containing the themed links as the values. The keys of the array contain some extra encoded information about the results. The format of the key is {level}-{num}{-active}. level is the depth within the menu tree of this list. num is the number within this array, used only to make the key unique. -active is appended if this element is in the active trail.
Related topics
3 calls to menu_primary_links()
- chameleon_page in themes/
chameleon/ chameleon.theme - menu_secondary_links in includes/
menu.inc - Returns an array containing the secondary links. Secondary links can be either a second level of the Primary links menu or generated from their own menu.
- phptemplate_page in themes/
engines/ phptemplate/ phptemplate.engine - Prepare the values passed to the theme_page function to be passed into a pluggable template engine.
File
- includes/
menu.inc, line 818 - API for the Drupal menu system.
Code
function menu_primary_links($start_level = 1, $pid = 0) {
if (!module_exist('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();
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}";
if (menu_in_active_trail_in_submenu($cid, $pid)) {
$index .= "-active";
}
$links[$index] = menu_item_link($cid);
$count++;
}
}
// Special case - provide link to admin/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'] = l(t('edit primary links'), 'admin/menu');
}
return $links;
}