_menu_helper_reset_get_reset_branches_recursive

custom/menu_helper/menu_helper_reset/menu_helper_reset.module, line 131

Versions
6
_menu_helper_reset_get_reset_branches_recursive(&$current_branch, &$reset_branches = array())

Recurse down the tree looking for a branch with a 'menu_helper_reset_depth'

Parameters

$current_branch The active trail branch of the menu tree.

$reset_branches An associative array of active trail branches that a reset depth and are pruned from the $current_branch.

▾ 2 functions call _menu_helper_reset_get_reset_branches_recursive()

menu_helper_reset_tree_page_data in custom/menu_helper/menu_helper_reset/menu_helper_reset.module
Get the data structure representing a named menu tree, based on the current page with any reset branches re-positioned.
_menu_helper_reset_get_reset_branches_recursive in custom/menu_helper/menu_helper_reset/menu_helper_reset.module
Recurse down the tree looking for a branch with a 'menu_helper_reset_depth'

Code

<?php
function _menu_helper_reset_get_reset_branches_recursive(&$current_branch, &$reset_branches = array()) {
  $keys = array_keys($current_branch);
  foreach ($keys as $key) {
    // Pointer for current link simplifies things a little
    $current_link =& $current_branch[$key]['link'];

    // Pointer for current below is useful since if the $current_link is reset the it will be pruned fron the $current_branch.
    $current_below =& $current_branch[$key]['below'];

    // Continue if we are not in the active menu trail
    if ( !$current_link['in_active_trail'] ) {
      continue;
    }

    // If current branch menu item has 'menu_helper_reset_depth'
    if ( isset($current_link['options']['menu_helper_reset']['depth']) ) {
      // If the depth is greater then current then it should be the first item at the current depth
      if ( $current_link['options']['menu_helper_reset']['depth'] > $current_link['depth']) {
        $current_link['options']['menu_helper_reset']['depth'] = $current_link['depth'];
      }
      // Add branch to reset array
      $reset_branches[$key] = $current_branch[$key];

      // Prune from current branch
      unset( $current_branch[$key] );
    }

    // Recurse downward collecting all reset branches
    if ($current_below) {
      _menu_helper_reset_get_reset_branches_recursive($current_below, $reset_branches);
    }
  }

  // Return the collection of reset branches
  return $reset_branches;
}
?>