Skip to content

Instantly share code, notes, and snippets.

@abulte
Created October 24, 2013 12:05
Show Gist options
  • Save abulte/7136038 to your computer and use it in GitHub Desktop.
Save abulte/7136038 to your computer and use it in GitHub Desktop.
Drupal 7 Fetch siblings of node in menu
<?php
// requires Menu Node API https://drupal.org/project/menu_node
// [ALB] ripped from submenutree.module
// Traverse down the tree to find our node, following in_active_trial
// This code stanza is loosely inspired by menu_set_active_trail()
$item = $current_item;
$tree = menu_tree_all_data($item['menu_name'], $item);
$my_tree = FALSE;
$parent_tree = FALSE;
list($key, $curr) = each($tree);
while ($curr) {
if ($curr['link']['href'] == $item['href']) {
$my_tree = $curr['below'];
$parent_tree = $tree;
// Clear the children in the parent_tree if it is not an expanded menu item
if (empty($parent_tree[$key]['link']['expanded'])) {
$parent_tree[$key]['below'] = array();
}
$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'];
}
list($key, $curr) = each($tree);
}
}
$siblings = array();
foreach ($parent_tree as $k => $v) {
if ($v['link']['mlid'] != $item['mlid']) {
$siblings[] = menu_node_get_node($v['link']['mlid']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment