You are here

function menu_tree_block_data in Menu Block 7.2

Same name and namespace in other branches
  1. 7.3 menu_block.module \menu_tree_block_data()

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

Parameters

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

Return value

array

1 call to menu_tree_block_data()
menu_tree_build in ./menu_block.module
Build a menu tree based on the provided configuration.

File

./menu_block.module, line 345
Provides configurable blocks of menu items.

Code

function menu_tree_block_data(array &$config) {

  // Determine the max depth based on level and depth setting.
  $max_depth = $config['depth'] == 0 ? NULL : min($config['level'] + $config['depth'] - 1, MENU_MAX_DEPTH);
  if ($config['expanded'] || $config['parent_mlid']) {

    // Get the full, un-pruned tree.
    if ($config['parent_mlid'] || !empty($config['depth_relative'])) {
      $tree = menu_tree_all_data($config['menu_name']);
    }
    else {
      $tree = menu_tree_all_data($config['menu_name'], NULL, $max_depth);
    }

    // And add the active trail data back to the full tree.
    menu_tree_add_active_path($tree);
  }
  else {
    if (!empty($config['depth_relative'])) {

      // Get the tree pruned for just the active trail.
      $tree = menu_tree_page_data($config['menu_name']);
    }
    else {
      $tree = menu_tree_page_data($config['menu_name'], $max_depth);
    }
  }

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

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

  // Prune the tree along the active trail to the specified level.
  if ($config['level'] > 1 || $config['parent_mlid']) {
    if ($config['parent_mlid']) {
      $parent_item = menu_link_load($config['parent_mlid']);
      if (!$parent_item) {
        watchdog('menu_block', "Menu block @delta is set to use parent menu link @plid but the menu link was not loadable or does not exist.", array(
          '@delta' => $config['delta'],
          '@plid' => $config['parent_mlid'],
        ), WATCHDOG_ERROR);
        $parent_item = NULL;
      }
      menu_tree_prune_tree($tree, $config['level'], $parent_item);
    }
    else {
      menu_tree_prune_tree($tree, $config['level']);
    }
  }

  // Prune the tree to the active menu item.
  if ($config['follow']) {
    menu_tree_prune_active_tree($tree, $config['follow']);
  }

  // If the menu-item-based tree is not "expanded", trim the tree to the active path.
  if ($config['parent_mlid'] && !$config['expanded']) {
    menu_tree_trim_active_path($tree);
  }

  // Trim the branches that extend beyond the specified depth.
  if ($config['depth'] > 0) {
    menu_tree_depth_trim($tree, $config['depth']);
  }

  // Sort the active path to the top of the tree.
  if ($config['sort']) {
    menu_tree_sort_active_path($tree);
  }
  return $tree;
}