You are here

function theme_admin_menu_links in Administration menu 7.3

Same name and namespace in other branches
  1. 8.3 admin_menu.module \theme_admin_menu_links()
  2. 6.3 admin_menu.module \theme_admin_menu_links()

Render a themed list of links.

Parameters

$variables:

  • elements: A renderable array of links using the following keys:

    • #attributes: Optional array of attributes for the list item, processed via drupal_attributes().
    • #title: Title of the link, passed to l().
    • #href: Optional path of the link, passed to l(). When omitted, the element's '#title' is rendered without link.
    • #description: Optional alternative text for the link, passed to l().
    • #options: Optional alternative text for the link, passed to l().

    The array key of each child element itself is passed as path for l().

4 theme calls to theme_admin_menu_links()
admin_menu_links_account in ./admin_menu.inc
Builds the account links.
admin_menu_links_icon in ./admin_menu.inc
Build icon menu links; mostly containing maintenance helpers.
admin_menu_links_search in ./admin_menu.inc
Build search widget.
admin_menu_links_users in ./admin_menu.inc
Builds user counter.

File

./admin_menu.module, line 747
Render an administrative menu as a dropdown menu at the top of the window.

Code

function theme_admin_menu_links($variables) {
  $destination =& drupal_static('admin_menu_destination');
  $elements = $variables['elements'];
  if (!isset($destination)) {
    $destination = drupal_get_destination();
    $destination = $destination['destination'];
  }

  // The majority of items in the menu are sorted already, but since modules
  // may add or change arbitrary items anywhere, there is no way around sorting
  // everything again. element_sort() is not sufficient here, as it
  // intentionally retains the order of elements having the same #weight,
  // whereas menu links are supposed to be ordered by #weight and #title.
  uasort($elements, 'admin_menu_element_sort');
  $elements['#sorted'] = TRUE;
  $output = '';
  foreach (element_children($elements) as $path) {

    // Early-return nothing if user does not have access.
    if (isset($elements[$path]['#access']) && !$elements[$path]['#access']) {
      continue;
    }

    // Initialized required values.
    $elements[$path]['#attributes'] = isset($elements[$path]['#attributes']) ? $elements[$path]['#attributes'] : array();
    $elements[$path]['#options'] = isset($elements[$path]['#options']) ? $elements[$path]['#options'] : array();

    // Render children to determine whether this link is expandable.
    if (isset($elements[$path]['#type']) || isset($elements[$path]['#theme']) || isset($elements[$path]['#pre_render'])) {
      $elements[$path]['#children'] = drupal_render($elements[$path]);
    }
    else {
      $elements[$path]['#children'] = theme('admin_menu_links', array(
        'elements' => $elements[$path],
      ));
      if (!empty($elements[$path]['#children'])) {
        $elements[$path]['#attributes']['class'][] = 'expandable';
      }
      if (isset($elements[$path]['#attributes']['class'])) {
        $elements[$path]['#attributes']['class'] = $elements[$path]['#attributes']['class'];
      }
    }
    $link = '';

    // Handle menu links.
    if (isset($elements[$path]['#href'])) {

      // Strip destination query string from href attribute and apply a CSS class
      // for our JavaScript behavior instead.
      if (isset($elements[$path]['#options']['query']['destination']) && $elements[$path]['#options']['query']['destination'] == $destination) {
        unset($elements[$path]['#options']['query']['destination']);
        $elements[$path]['#options']['attributes']['class'][] = 'admin-menu-destination';
      }

      // If the path has an alias replace the href with the alias.
      if (module_exists('path')) {
        if ($alias = drupal_get_path_alias($elements[$path]['#href'])) {
          $elements[$path]['#href'] = $alias;
        }
      }
      $link = l($elements[$path]['#title'], $elements[$path]['#href'], $elements[$path]['#options']);
    }
    elseif (!isset($elements[$path]['#type']) && isset($elements[$path]['#title'])) {
      if (!empty($elements[$path]['#options']['html'])) {
        $title = $elements[$path]['#title'];
      }
      else {
        $title = check_plain($elements[$path]['#title']);
      }
      $attributes = '';
      if (isset($elements[$path]['#options']['attributes'])) {
        $attributes = drupal_attributes($elements[$path]['#options']['attributes']);
      }
      $link = '<span' . $attributes . '>' . $title . '</span>';
    }
    $output .= '<li' . drupal_attributes($elements[$path]['#attributes']) . '>';
    $output .= $link . $elements[$path]['#children'];
    $output .= '</li>';
  }

  // @todo #attributes probably required for UL, but already used for LI.
  // @todo Use $element['#children'] here instead.
  if ($output) {
    $elements['#wrapper_attributes']['class'][] = 'dropdown';
    $attributes = drupal_attributes($elements['#wrapper_attributes']);
    $output = "\n" . '<ul' . $attributes . '>' . $output . '</ul>';
  }
  return $output;
}