You are here

function accordion_menu_output in Accordion Menu 7

Same name and namespace in other branches
  1. 6 includes/view.inc \accordion_menu_output()

Returns a render array of the accordion menu tree.

Parameters

array $tree: An associative array of the menu tree.

array $config: The configuration settings for the menu block.

string $active_menu: The active menu item for the JS settings.

Return value

array An render array of the menu tree.

See also

menu_tree_output()

1 call to accordion_menu_output()
_accordion_menu_block_view in includes/view.inc
Implements hook_block_view().

File

includes/view.inc, line 188
Provides view routines.

Code

function accordion_menu_output(array $tree, array $config, &$active_menu = '') {
  $build = $items = array();

  // Pull out just the menu items we are going to render so that we
  // get an accurate count for the first/last classes.
  foreach ($tree as $data) {
    if ($data['link']['access'] && !$data['link']['hidden']) {
      $items[] = $data;
    }
  }
  $item_count = count($items);
  $flip = array(
    'even' => 'odd',
    'odd' => 'even',
  );
  $zebra = 'even';
  foreach ($items as $i => $data) {
    $subtree = _accordion_menu_subtree($data['link']);
    $subtree = menu_tree_output($subtree);

    // Add CSS classes.
    $class = array();
    $class[] = 'accordion-header accordion-header-' . ($i + 1);
    if ($i == 0) {
      $class[] = 'first';
    }
    if ($i == $item_count - 1) {
      $class[] = 'last';
    }
    if ($subtree) {
      $class[] = 'has-children';
    }
    else {
      $class[] = 'no-children';
    }
    if ($data['link']['in_active_trail']) {
      $class[] = 'active-trail';
      $data['link']['localized_options']['attributes']['class'][] = 'active-trail';
    }
    if ($data['link']['href'] == $_GET['q'] || $data['link']['href'] == '<front>' && drupal_is_front_page()) {
      $class[] = 'active';
    }
    $class[] = $zebra = $flip[$zebra];
    $class[] = 'menu-mlid-' . $data['link']['mlid'];

    // Distinguish our "span" element from that added by ui accordion.
    $data['link']['localized_options']['attributes']['class'][] = 'accordion-link';

    // Allow menu-specific theme overrides.
    $element['#theme'] = array(
      'accordion_menu_header__' . str_replace('-', '_', $config['delta']),
      'accordion_menu_header__' . str_replace('-', '_', $config['menu_name']),
      'accordion_menu_header',
    );
    $element['#attributes']['class'] = $class;
    $element['#title'] = $data['link']['title'];
    $element['#href'] = $data['link']['href'];
    $element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
    $element['#below'] = $subtree;
    $element['#original_link'] = $data['link'];
    $element['#bid'] = array(
      'module' => 'accordion_menu',
      'delta' => $config['delta'],
    );
    $element['#config'] = $config;
    $element['#count'] = $i + 1;

    // Index using the link's unique mlid.
    $build[$data['link']['mlid']] = $element;
    if ($data['link']['in_active_trail'] == '1') {
      $active_menu = $i;
    }
  }
  if ($build) {

    // Make sure drupal_render() does not re-order the links.
    $build['#sorted'] = TRUE;
  }
  return $build;

  // Add class to handle flash of unstyled content in IE 7 and 8.
  // @todo Reincorporate this.
  $output = str_replace('ul class="menu"', 'ul class="menu hide-at-first"', $output);
}