You are here

function _submenutree_block_extended_primary_links in Submenu Tree 7

Same name and namespace in other branches
  1. 6 submenutree.module \_submenutree_block_extended_primary_links()

Return block of extended primary links

1 call to _submenutree_block_extended_primary_links()
submenutree_block_view in ./submenutree.module
Implements of hook_block_view().

File

./submenutree.module, line 434
Submenu Tree

Code

function _submenutree_block_extended_primary_links() {

  // Choose the appropriate menu root
  $primary_name = variable_get('menu_main_links_source', 'main-menu');
  $secondary_name = variable_get('menu_secondary_links_source', 'user-menu');
  if ($primary_name) {
    $menu_name = $primary_name;
    if ($primary_name != $secondary_name) {
      $level = 1;
    }
    else {
      $level = 2;
    }

    // Select the third level of the primary menu
  }
  else {
    if ($secondary_name) {
      $menu_name = $secondary_name;
      $level = 1;

      // Select the second level of the secondary menu
    }
    else {
      break;
    }
  }

  // Loosely derived from menu_navigation_links()
  $parent = FALSE;
  $tree = menu_tree_page_data($menu_name);

  // Go down the active trail until the right level is reached.
  while ($level-- > 0 && $tree) {

    // Loop through the current level's items until we find one that is in trail.
    while ($item = array_shift($tree)) {
      if ($item['link']['in_active_trail']) {
        $parent = $item;

        // If the item is in the active trail, we continue in the subtree.
        $tree = empty($item['below']) ? array() : $item['below'];
        break;
      }
    }
  }
  if (!empty($parent)) {
    $title = $parent['link']['title'];
    $output = drupal_render(menu_tree_output($tree));
  }
  if (!empty($output)) {
    $block = array(
      'subject' => $title,
      'content' => $output,
    );
    return $block;
  }
}