You are here

function menu_primary_links in Drupal 5

Same name and namespace in other branches
  1. 4 includes/menu.inc \menu_primary_links()
  2. 6 includes/menu.inc \menu_primary_links()

Returns an array containing the primary links. Can optionally descend from the root of the Primary links menu towards the current node for a specified number of levels and return that submenu. Used to generate a primary/secondary menu from different levels of one menu.

Parameters

$start_level: This optional parameter can be used to retrieve a context-sensitive array of links at $start_level levels deep into the Primary links menu. The default is to return the top-level links.

$pid: The parent menu ID from which to search for children. Defaults to the menu_primary_menu setting.

Return value

A nested array of links and their properties. The keys of the array contain some extra encoded information about the results. The format of the key is {level}-{num}{-active}. level is the depth within the menu tree of this list. num is the number within this array, used only to make the key unique. -active is appended if this element is in the active trail.

Related topics

3 calls to menu_primary_links()
chameleon_page in themes/chameleon/chameleon.theme
menu_secondary_links in includes/menu.inc
Returns an array containing the secondary links. Secondary links can be either a second level of the Primary links menu or generated from their own menu.
phptemplate_page in themes/engines/phptemplate/phptemplate.engine
Prepare the values passed to the theme_page function to be passed into a pluggable template engine. Uses the arg() function to generate a series of page template files suggestions based on the current path. If none are found, the default page.tpl.php…

File

includes/menu.inc, line 832
API for the Drupal menu system.

Code

function menu_primary_links($start_level = 1, $pid = 0) {
  if (!module_exists('menu')) {
    return NULL;
  }
  if (!$pid) {
    $pid = variable_get('menu_primary_menu', 0);
  }
  if (!$pid) {
    return NULL;
  }
  if ($start_level < 1) {
    $start_level = 1;
  }
  if ($start_level > 1) {
    $trail = _menu_get_active_trail_in_submenu($pid);
    if (!$trail) {
      return NULL;
    }
    else {
      $pid = $trail[$start_level - 1];
    }
  }
  $menu = menu_get_menu();
  $links = array();
  if ($pid && is_array($menu['visible'][$pid]) && isset($menu['visible'][$pid]['children'])) {
    $count = 1;
    foreach ($menu['visible'][$pid]['children'] as $cid) {
      $index = "menu-{$start_level}-{$count}-{$pid}";
      if (menu_in_active_trail_in_submenu($cid, $pid)) {
        $index .= "-active";
      }
      $links[$index] = menu_item_link($cid, FALSE);
      $count++;
    }
  }

  // Special case - provide link to admin/build/menu if primary links is empty.
  if (empty($links) && $start_level == 1 && $pid == variable_get('menu_primary_menu', 0) && user_access('administer menu')) {
    $links['1-1'] = array(
      'title' => t('Edit primary links'),
      'href' => 'admin/build/menu',
    );
  }
  return $links;
}