You are here

function admin_menu_links_menu in Administration menu 8.3

Same name and namespace in other branches
  1. 6.3 admin_menu.inc \admin_menu_links_menu()
  2. 7.3 admin_menu.inc \admin_menu_links_menu()

Build the administration menu as renderable menu links.

Parameters

$tree: A data structure representing the administration menu tree as returned from menu_tree_all_data().

Return value

The complete administration menu, suitable for theme_admin_menu_links().

See also

theme_admin_menu_links()

admin_menu_menu_alter()

3 calls to admin_menu_links_menu()
admin_menu_admin_menu_output_build in ./admin_menu.module
Implements hook_admin_menu_output_build().
admin_menu_links_icon in ./admin_menu.inc
Build icon menu links; mostly containing maintenance helpers.
admin_menu_output in ./admin_menu.module
Build the administration menu output.

File

./admin_menu.inc, line 365
Menu builder functions for Administration menu.

Code

function admin_menu_links_menu($tree) {
  $links = [];
  foreach ($tree as $data) {

    // Skip items that are inaccessible, invisible, or link to their parent.
    // (MENU_DEFAULT_LOCAL_TASK), and MENU_CALLBACK-alike items that should only
    // appear in the breadcrumb.
    if (!$data['link']['access'] || $data['link']['type'] & MENU_LINKS_TO_PARENT || $data['link']['type'] == MENU_VISIBLE_IN_BREADCRUMB || $data['link']['hidden'] == 1) {
      continue;
    }

    // Hide 'Administer' and make child links appear on this level.
    // @todo Make this configurable.
    if ($data['link']['router_path'] == 'admin') {
      if ($data['below']) {
        $links = array_merge($links, admin_menu_links_menu($data['below']));
      }
      continue;
    }

    // Omit alias lookups.
    $data['link']['localized_options']['alias'] = TRUE;

    // Remove description to prevent mouseover tooltip clashes.
    unset($data['link']['localized_options']['attributes']['title']);

    // Make action links (typically "Add ...") appear first in dropdowns.
    // They might appear first already, but only as long as there is no link
    // that comes alphabetically first (e.g., a node type with label "Ad").
    if ($data['link']['type'] & MENU_IS_LOCAL_ACTION) {
      $data['link']['weight'] -= 1000;
    }
    $links[$data['link']['href']] = [
      '#title' => $data['link']['title'],
      '#href' => $data['link']['href'],
      '#options' => $data['link']['localized_options'],
      '#weight' => $data['link']['weight'],
    ];

    // Recurse to add any child links.
    $children = [];
    if ($data['below']) {
      $children = admin_menu_links_menu($data['below']);
      $links[$data['link']['href']] += $children;
    }

    // Handle links pointing to category/overview pages.
    if ($data['link']['page_callback'] == 'system_admin_menu_block_page' || $data['link']['page_callback'] == 'system_admin_config_page') {

      // Apply a marker for others to consume.
      $links[$data['link']['href']]['#is_category'] = TRUE;

      // Automatically hide empty categories.
      // Check for empty children first for performance. Only when non-empty
      // (typically 'admin/config'), check whether children are accessible.
      if (empty($children) || !element_get_visible_children($children)) {
        $links[$data['link']['href']]['#access'] = FALSE;
      }
    }
  }
  return $links;
}