function theme_admin_menu_links

nittany7 admin_menu.module theme_admin_menu_links($variables)
cis7 admin_menu.module theme_admin_menu_links($variables)
mooc7 admin_menu.module theme_admin_menu_links($variables)

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().

File

modules/contrib/admin_menu/admin_menu.module, line 635
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;
    }
    $elements[$path] += array(
      '#attributes' => array(),
      '#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';
      }

      $link = l($elements[$path]['#title'], $elements[$path]['#href'], $elements[$path]['#options']);
    }
    // Handle plain text items, but do not interfere with menu additions.
    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;
}