You are here

function responsive_menu_tree_block_data in Responsive and off-canvas menu 7

Same name and namespace in other branches
  1. 7.3 includes/responsive_menu.menu.inc \responsive_menu_tree_block_data()
  2. 7.2 includes/responsive_menu.menu.inc \responsive_menu_tree_block_data()

Gets the data structure representing a menu tree for the given configuration.

Parameters

$config: See the $config param of menu_tree_build().

2 calls to responsive_menu_tree_block_data()
responsive_menu_page_build in ./responsive_menu.module
Implements hook_page_build().
responsive_menu_tree_build in includes/responsive_menu.menu.inc
Build a menu tree based.

File

includes/responsive_menu.menu.inc, line 147
Functions which process the menu.

Code

function responsive_menu_tree_block_data($menu_name) {

  // The maximum depth the CSS menu can handle is 3.
  $max_depth = NULL;
  $tree = menu_tree_all_data($menu_name, NULL, $max_depth);

  // And add the active trail data back to the full tree.
  $menu_item = current($tree);
  $tree_with_trail = menu_tree_page_data($menu_item['link']['menu_name'], $max_depth);

  // To traverse the original tree down the active trail, we use a pointer.
  $subtree_pointer =& $tree;

  // Find each key in the active trail.
  while ($tree_with_trail) {
    foreach ($tree_with_trail as $key => &$value) {
      if ($tree_with_trail[$key]['link']['in_active_trail'] && isset($subtree_pointer[$key])) {

        // Set the active trail info in the original tree.
        $subtree_pointer[$key]['link']['in_active_trail'] = TRUE;

        // Continue in the subtree, if it exists.
        $tree_with_trail =& $tree_with_trail[$key]['below'];
        $subtree_pointer =& $subtree_pointer[$key]['below'];
        break;
      }
      else {
        unset($tree_with_trail[$key]);
      }
    }
  }

  // Allow alteration of the tree and config before we begin operations on it.
  drupal_alter('responsive_menu_tree', $tree, $menu_name);

  // Localize the tree.
  if (module_exists('i18n_menu')) {
    $tree = i18n_menu_localize_tree($tree);
  }

  // Trim the branches that extend beyond the specified depth.
  responsive_menu_tree_depth_trim($tree, $max_depth);
  return $tree;
}