function nodehierarchy_menu_overview_form in Node Hierarchy 7.4
Same name and namespace in other branches
- 6.3 nodehierarchy.module \nodehierarchy_menu_overview_form()
- 6.2 nodehierarchy.module \nodehierarchy_menu_overview_form()
- 7.2 nodehierarchy.module \nodehierarchy_menu_overview_form()
Form for editing an entire menu tree at once.
Shows for one menu the menu items accessible to the current user and relevant operations. This is a clone of the menu.module function menu_overview_form but with nodehierarchy items not loaded if they don't not have a menu presence.
1 string reference to 'nodehierarchy_menu_overview_form'
- nodehierarchy_menu_alter in nodehierarchy_menu/
nodehierarchy_menu.module - Implements hook_menu_alter().
File
- nodehierarchy_menu/
nodehierarchy_menu.module, line 34 - Create menu items for a node based on the Node Hierarchy.
Code
function nodehierarchy_menu_overview_form($form, &$form_state, $menu, $plid = 0) {
if (!module_exists('menu')) {
return array();
}
global $menu_admin;
$query = db_select('menu_links', 'ml');
$query
->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
$query
->fields('m', array(
'load_functions',
'to_arg_functions',
'access_callback',
'access_arguments',
'page_arguments',
'delivery_callback',
'title',
'title_callback',
'title_arguments',
'type',
'description',
))
->fields('ml')
->condition('ml.menu_name', $menu['menu_name']);
$or = db_or()
->condition('ml.plid', $plid);
// If we're in thea sub-menu, put together the rest of the tree.
if ($plid) {
$or
->condition('ml.plid', 0);
$or
->condition('ml.mlid', $plid);
// Get the grandparent mlid so we can go up one more level for back-navigation.
$gplid = $plid;
while ($gplid = db_select('menu_links', 'ml')
->fields('ml', array(
'plid',
))
->condition('mlid', $gplid)
->execute()
->fetchField()) {
$or
->condition('ml.mlid', $gplid);
$or
->condition('ml.plid', $gplid);
}
}
$query
->condition($or);
for ($i = 1; $i <= 9; $i++) {
$query
->orderBy('p' . $i, 'ASC');
}
$result = $query
->execute();
$links = array();
foreach ($result as $item) {
$links[] = (array) $item;
}
$tree = menu_tree_data($links);
$node_links = array();
menu_tree_collect_node_links($tree, $node_links);
// We indicate that a menu administrator is running the menu access check.
$menu_admin = TRUE;
menu_tree_check_access($tree, $node_links);
$menu_admin = FALSE;
$form = array_merge($form, _menu_overview_tree_form($tree));
$form['#menu'] = $menu;
// Add a breadcrumb
// Replace the regular links with links to the sub form.
foreach (element_children($form) as $id) {
$form[$id]['title']['#markup'] = l($form[$id]['#item']['title'], 'admin/structure/menu/manage/' . $menu['menu_name'] . '/' . $form[$id]['#item']['mlid']);
}
if (element_children($form)) {
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
}
else {
$form['#empty_text'] = t('There are no menu links yet. <a href="@link">Add link</a>.', array(
'@link' => url('admin/structure/menu/manage/' . $form['#menu']['menu_name'] . '/add'),
));
}
// Set the form handlers so the behaviour is the same as the regular menu form.
$form['#submit'][] = 'menu_overview_form_submit';
$form['#submit'][] = 'nodehierarchy_menu_overview_form_submit';
return $form;
}