_menu_append_contextual_items
- Versions
- 4.6 – 5
_menu_append_contextual_items()
Account for menu items that are only defined at certain paths, so will not be cached.
We don't support the full range of menu item options for these menu items. We don't support MENU_VISIBLE_IF_HAS_CHILDREN, and we require parent items to be declared before their children.
Code
includes/menu.inc, line 1194
<?php
function _menu_append_contextual_items() {
global $_menu;
// Build a sequential list of all menu items.
$menu_item_list = module_invoke_all('menu', FALSE);
// Menu items not in the DB get temporary negative IDs.
$temp_mid = min(array_keys($_menu['items'])) - 1;
$new_items = array();
foreach ($menu_item_list as $item) {
if (isset($item['callback'])) {
$_menu['callbacks'][$item['path']] = array('callback' => $item['callback']);
if (isset($item['callback arguments'])) {
$_menu['callbacks'][$item['path']]['callback arguments'] = $item['callback arguments'];
}
}
unset($item['callback']);
unset($item['callback arguments']);
if (!isset($_menu['path index'][$item['path']])) {
if (!isset($item['path'])) {
$item['path'] = '';
}
if (!isset($item['type'])) {
$item['type'] = MENU_NORMAL_ITEM;
}
if (!isset($item['weight'])) {
$item['weight'] = 0;
}
$_menu['items'][$temp_mid] = $item;
$_menu['path index'][$item['path']] = $temp_mid;
$new_items[$temp_mid] = $item;
$temp_mid--;
}
else {
$mid = $_menu['path index'][$item['path']];
if ($_menu['items'][$mid]['type'] & MENU_CREATED_BY_ADMIN) {
$_menu['items'][$mid]['access'] = $item['access'];
if (isset($_menu['items'][$mid]['callback'])) {
$_menu['items'][$mid]['callback'] = $item['callback'];
}
if (isset($_menu['items'][$mid]['callback arguments'])) {
$_menu['items'][$mid]['callback arguments'] = $item['callback arguments'];
}
}
}
}
// Establish parent-child relationships.
_menu_find_parents($new_items);
// Add new items to the visible tree if necessary.
foreach ($new_items as $mid => $item) {
$item = $_menu['items'][$mid];
if (($item['type'] & MENU_VISIBLE_IN_TREE) && _menu_item_is_accessible($mid)) {
$pid = $item['pid'];
while ($pid && !isset($_menu['visible'][$pid])) {
$pid = $_menu['items'][$pid]['pid'];
}
$_menu['visible'][$mid] = array('title' => $item['title'], 'path' => $item['path'], 'pid' => $pid);
$_menu['visible'][$pid]['children'][] = $mid;
usort($_menu['visible'][$pid]['children'], '_menu_sort');
}
}
}
?>Login or register to post comments 