You are here

function ultimenu_tree_output in Ultimenu 7

We use tree for future integration with regular dropdown so far.

This is a copy of menu_tree_output() with additional classes added to the output. This is a copy of the amazing menu_block.module with a tweak to hold a region inside data below, and a few other modifications.

Parameters

array $tree: The array data structure representing the tree as from menu_tree_data.

array $config: The array config for the current Ultimenu block.

Return value

string The rendered HTML of that data structure.

1 call to ultimenu_tree_output()
ultimenu_block_view in ./ultimenu.module
Implements hook_block_view().

File

./ultimenu.module, line 201
Build Ultimenu regions based on enabled menu and its available menu items.

Code

function ultimenu_tree_output(&$tree, $config = array()) {
  $build = array();
  $items = array();

  // Create context if no config was provided.
  if (empty($config)) {
    $config['delta'] = 0;

    // Grab any menu item to find the menu_name for this tree.
    $menu_item = current($tree);
    $config['menu_name'] = $menu_item['link']['menu_name'];
  }
  $goodies = ultimenu_get_settings('goodies');
  $hook_menu_name = str_replace('-', '_', $config['menu_name']);

  // 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 $key => &$value) {
    if (!$tree[$key]['link']['hidden']) {
      $items[] = $tree[$key];
    }
  }
  $num_items = count($items);
  foreach ($items as $i => &$data) {
    $class = array();
    if ($i == 0) {
      $class[] = 'first';
    }
    if ($i == $num_items - 1) {
      $class[] = 'last';
    }

    // Set a class if the link is in the active trail.
    // @todo drop if we don't support submenus at all via menu_navigation_links.
    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';
    }

    // Allow menu-specific theme overrides.
    // We don't use regular menu_link to avoid issue with a theme that provides
    // a fully customized menu_link.
    $element['#theme'] = array(
      'ultimenu_link__' . $hook_menu_name,
      'ultimenu_link',
    );
    $title_stripped = isset($data['link']['title']) ? strip_tags($data['link']['title']) : '';
    $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['#original_link'] = $data['link'];
    $element['#bid'] = array(
      'module' => 'ultimenu',
      'delta' => $config['delta'],
      'region' => NULL,
    );
    $element['#below'] = '';

    // Flyout regions.
    // Attach our Ultimenu region if we can find blocks in this item.
    $menu_item_id = !empty($goodies['ultimenu-mlid']) ? $data['link']['mlid'] : ultimenu_truncate_menu_property($title_stripped, 28);
    $menu_name_id = ultimenu_truncate_menu_property($config['menu_name']);
    $variables['region'] = 'ultimenu_' . $menu_name_id . '_' . $menu_item_id;

    // @todo add option to contain submenus, or better leave it to menu_block.
    // @todo a better flag. 744
    if ($regions = ultimenu_get_settings('regions')) {
      if (!empty($regions[$variables['region']])) {
        $element['#bid']['region'] = $variables['region'];
        if (!$element['#bid']['region']) {
          continue;
        }
        $variables['config'] = $config;
        $element['#below'] = ultimenu_build_data_region($variables);
      }
    }

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

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