menu_block.follow.inc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @file
  4. * Provides active menu item pruning.
  5. */
  6. /**
  7. * Prune a tree so that it begins at the active menu item.
  8. *
  9. * @param $tree
  10. * array The menu tree to prune.
  11. * @param $level
  12. * string The level which the tree will be pruned to: 'active' or 'child'.
  13. * @return
  14. * void
  15. */
  16. function _menu_tree_prune_active_tree(&$tree, $level) {
  17. do {
  18. $found_active_trail = FALSE;
  19. // Examine each element at this level for the active trail.
  20. foreach ($tree AS $key => &$value) {
  21. if ($tree[$key]['link']['in_active_trail']) {
  22. $found_active_trail = TRUE;
  23. // If the active trail item has children, examine them.
  24. if ($tree[$key]['below']) {
  25. // If we are pruning to the active menu item's level, check if this
  26. // is the active menu item by checking its children.
  27. if ($level == 'active') {
  28. foreach ($tree[$key]['below'] AS $child_key => &$value) {
  29. if ($tree[$key]['below'][$child_key]['link']['in_active_trail']) {
  30. // Get the title for the pruned tree.
  31. menu_block_set_title($tree[$key]['link']);
  32. $tree = $tree[$key]['below'];
  33. // Continue in the pruned tree.
  34. break 2;
  35. }
  36. }
  37. // If we've found the active item, we're done.
  38. break 2;
  39. }
  40. // Set the title for the pruned tree.
  41. menu_block_set_title($tree[$key]['link']);
  42. // If we are pruning to the children of the active menu item, just
  43. // prune the tree to the children of the item in the active trail.
  44. $tree = $tree[$key]['below'];
  45. // Continue in the pruned tree.
  46. break;
  47. }
  48. // If the active menu item has no children, we're done.
  49. else {
  50. if ($level == 'child') {
  51. $tree = array();
  52. }
  53. break 2;
  54. }
  55. }
  56. }
  57. } while ($found_active_trail);
  58. }