menu_local_tasks
- 6
menu_local_tasks($level = 0, $return_root = FALSE)
- 7
menu_local_tasks($level = 0)
Collects the local tasks (tabs) for a given level.
Parameters
$level
The level of tasks you ask for. Primary tasks are 0, secondary are 1.
$return_root
Whether to return the root path for the current page.
Return value
Themed output corresponding to the tabs of the requested level, or
router path if $return_root == TRUE. This router path corresponds to
a parent tab, if the current page is a default local task.
Related topics
- Menu system
- Define the navigation menus, and route page requests to code based on URLs.
Code
drupal/includes/menu.inc, line 1312
<?php
function menu_local_tasks($level = 0, $return_root = FALSE) {
static $tabs;
static $root_path;
if (!isset($tabs)) {
$tabs = array();
$router_item = menu_get_item();
if (!$router_item || !$router_item['access']) {
return '';
}
$result = db_query("SELECT * FROM {menu_router} WHERE tab_root = '%s' ORDER BY weight, title", $router_item['tab_root']);
$map = arg();
$children = array();
$tasks = array();
$root_path = $router_item['path'];
while ($item = db_fetch_array($result)) {
_menu_translate($item, $map, TRUE);
if ($item['tab_parent']) {
$children[$item['tab_parent']][$item['path']] = $item;
}
$tasks[$item['path']] = $item;
}
$path = $router_item['path'];
$depth = 1001;
while (isset($children[$path])) {
$tabs_current = '';
$next_path = '';
$count = 0;
foreach ($children[$path] as $item) {
if ($item['access']) {
$count++;
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']);
$link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
$tabs_current .= theme('menu_local_task', $link, TRUE);
$next_path = $item['path'];
}
else {
$link = theme('menu_item_link', $item);
$tabs_current .= theme('menu_local_task', $link);
}
}
}
$path = $next_path;
$tabs[$depth]['count'] = $count;
$tabs[$depth]['output'] = $tabs_current;
$depth++;
}
$parent = $router_item['tab_parent'];
$path = $router_item['path'];
$current = $router_item;
$depth = 1000;
while (isset($children[$parent])) {
$tabs_current = '';
$next_path = '';
$next_parent = '';
$count = 0;
foreach ($children[$parent] as $item) {
if ($item['access']) {
$count++;
if ($item['type'] == MENU_DEFAULT_LOCAL_TASK) {
for ($p = $item['tab_parent']; $tasks[$p]['type'] == MENU_DEFAULT_LOCAL_TASK; $p = $tasks[$p]['tab_parent']);
$link = theme('menu_item_link', array('href' => $tasks[$p]['href']) + $item);
if ($item['path'] == $router_item['path']) {
$root_path = $tasks[$p]['path'];
}
}
else {
$link = theme('menu_item_link', $item);
}
if ($item['path'] == $path) {
$tabs_current .= theme('menu_local_task', $link, TRUE);
$next_path = $item['tab_parent'];
if (isset($tasks[$next_path])) {
$next_parent = $tasks[$next_path]['tab_parent'];
}
}
else {
$tabs_current .= theme('menu_local_task', $link);
}
}
}
$path = $next_path;
$parent = $next_parent;
$tabs[$depth]['count'] = $count;
$tabs[$depth]['output'] = $tabs_current;
$depth--;
}
ksort($tabs);
$tabs = array_values($tabs);
}
if ($return_root) {
return $root_path;
}
else {
return (isset($tabs[$level]) && $tabs[$level]['count'] > 1) ? $tabs[$level]['output'] : '';
}
}
?>