function submenutree_node_view in Submenu Tree 7.2
Same name and namespace in other branches
- 7 submenutree.module \submenutree_node_view()
Implements hook_node_view().
File
- ./
submenutree.module, line 387 - Primarily Drupal hooks and processing the Submenu Tree display.
Code
function submenutree_node_view($node, $view_mode, $langcode) {
if ($view_mode == 'full' && node_is_page($node) && (!empty($node->submenutree_enable) || !empty($node->siblingmenutree_enable))) {
$mlid = 0;
// Other modules may override which mlid to use. Use the first available value.
foreach (module_implements('submenutree_mlid') as $module) {
$function = $module . '_submenutree_mlid';
if ($mlid = $function($node)) {
break;
}
}
// Else, give priority to the default menu defined by the Menu module.
// This stanza is from menu_node_prepare()
if (!$mlid) {
// Give priority to the default menu
$menu_name = variable_get('menu_parent_' . $node->type, 'main-menu:0');
$menu_name = explode(':', $menu_name);
$menu_name = $menu_name[0];
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
':path' => 'node/' . $node->nid,
':menu_name' => $menu_name,
))
->fetchField();
}
// Check all menus if a link does not exist in the default menu.
if (!$mlid) {
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
':path' => 'node/' . $node->nid,
))
->fetchField();
}
if ($mlid) {
$item = menu_link_load($mlid);
$tree = menu_tree_all_data($item['menu_name'], $item);
// Traverse down the tree to find our node, following in_active_trial
// This code stanza is loosely inspired by menu_set_active_trail()
$my_tree = FALSE;
$parent_tree = FALSE;
$curr = current($tree);
$key = key($tree);
while ($curr) {
if ($curr['link']['href'] == $item['href']) {
$my_tree = $curr['below'];
$parent_tree = $tree;
// Remove the current node from the parent tree, since we only want to
// display the siblings from the same level.
unset($parent_tree[$key]);
$curr = FALSE;
}
else {
// Move to the child link if it's in the active trail.
if ($curr['below'] && $curr['link']['in_active_trail']) {
$tree = $curr['below'];
}
$key = key($tree);
$curr = current($tree);
next($tree);
}
}
// Sanity check that we did find something
if ($my_tree && $node->submenutree_enable) {
_submenutree_menutree_view($node, 'submenutree', $my_tree);
}
if ($parent_tree && $node->siblingmenutree_enable) {
_submenutree_menutree_view($node, 'siblingmenutree', $parent_tree);
}
}
}
}