You are here

function theme_mmenu_tree in Mobile sliding menu 7.2

Same name and namespace in other branches
  1. 8 mmenu.module \theme_mmenu_tree()
  2. 7.3 mmenu.module \theme_mmenu_tree()
  3. 7 mmenu.module \theme_mmenu_tree()

Returns HTML for a wrapper for a mmenu tree.

Parameters

array $block: An associative array containing:

  • tree: An array containing the tree's items.
  • reset: An boolean to determine if needs to reset the static variable.
1 theme call to theme_mmenu_tree()
template_preprocess_mmenu in ./mmenu.module
Processes variables for mmenu.tpl.php.

File

./mmenu.module, line 1063
Primarily Drupal hooks and global API functions to manipulate mmenus.

Code

function theme_mmenu_tree(array $block = array(
  'tree' => array(),
  'reset' => FALSE,
  'depth' => 1,
)) {
  $tree = $block['tree'];
  $reset = $block['reset'];
  $depth = $block['depth'];

  // Don't render if block content is empty.
  if (count($tree) <= 0) {
    return '';
  }
  static $mmenu_output = '';
  if ($reset) {
    $mmenu_output = '';
  }
  foreach ($tree as $item) {
    $cur_path = url($_GET['q']);
    $menu_path = check_url(url($item['link']['link_path']));

    // Adds classes to li in order to do more customization changes.
    $li_class = array();
    $li_class[] = 'mmenu-mm-list-mlid-' . $item['link']['mlid'];
    $my_menu_path = $item['link']['link_path'];
    $my_menu_path = trim($my_menu_path, '<');
    $my_menu_path = trim($my_menu_path, '>');
    $my_menu_path = trim($my_menu_path, '/');
    $my_menu_path = str_replace('/', '-', $my_menu_path);
    if (!empty($my_menu_path)) {
      $li_class[] = 'mmenu-mm-list-path-' . check_plain($my_menu_path);
    }
    if ($cur_path == $menu_path) {
      $li_class[] = 'active-trail';
    }

    // Gets the classes from the menu attributes.
    if (isset($item['link']['options']['attributes']['class']) && count($item['link']['options']['attributes']['class']) > 0) {
      $li_class = array_merge($li_class, $item['link']['options']['attributes']['class']);
    }
    $icon_class = mmenu_get_icon_class('path', $item['link']['link_path']);

    // In order to support the special_menu_items and menu_firstchild modules.
    $subopen_link_class = '';
    if (in_array($item['link']['link_path'], array(
      '<nolink>',
      '<firstchild>',
    ))) {
      $menu_path = 'javascript:void(0);';
      $subopen_link_class = 'mmenu-mm-subopen';
    }
    $mmenu_output .= '<li class="' . implode(' ', $li_class) . '"><a href="' . $menu_path . '" class="mmenu-mm-list ' . $subopen_link_class . '"><i class="' . $icon_class . '"></i><span class="mmenu-block-title">' . $item['link']['link_title'] . '</span></a>';
    if (isset($item['below']) && count($item['below']) > 0) {
      $mmenu_output .= '<ul class="mmenu-mm-list-level-' . ($depth + 1) . '">';
      theme('mmenu_tree', array(
        'tree' => $item['below'],
        'reset' => FALSE,
        'depth' => $depth + 1,
      ));
      $mmenu_output .= '</ul>';
    }
    $mmenu_output .= '</li>';
  }
  return '<ul class="mmenu-mm-list-level-' . $depth . '">' . $mmenu_output . '</ul>';
}