You are here

function theme_mmenu_tree in Mobile sliding menu 8

Same name and namespace in other branches
  1. 7.3 mmenu.module \theme_mmenu_tree()
  2. 7 mmenu.module \theme_mmenu_tree()
  3. 7.2 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 string reference to 'theme_mmenu_tree'
mmenu_theme in ./mmenu.module
Implements hook_theme().
1 theme call to theme_mmenu_tree()
template_preprocess_mmenu in ./mmenu.module
Processes variables for mmenu.tpl.php.

File

./mmenu.module, line 813
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 = \Drupal::service('path.current')
      ->getPath();
    $menu_path = $item->link
      ->getUrlObject()
      ->toString();

    // Adds classes to li in order to do more customization changes.

    //$mlid = $item->link->getMetadata()['entity_id'] ? $item->link->getMetadata()['entity_id'] : '0';
    $li_class = array();

    //$li_class[] = 'mmenu-mm-list-mlid-' . $mlid;
    $my_menu_path = $item->link
      ->getUrlObject()
      ->toString();
    $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-' . Html::escape($my_menu_path);
    }
    if ($cur_path == $menu_path) {
      $li_class[] = 'active-trail';
    }

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

    // In order to support the special_menu_items and menu_firstchild modules.
    $subopen_link_class = '';
    if (in_array($my_menu_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
      ->getTitle() . '</span></a>';
    if (!empty($item->subtree)) {
      $mmenu_output .= '<ul class="mmenu-mm-list-level-' . ($depth + 1) . '">';
      $subtree = array(
        '#theme' => 'mmenu_tree',
        '#tree' => $item->subtree,
        '#reset' => FALSE,
        '#depth' => $depth + 1,
      );
      render($subtree);
      $mmenu_output .= '</ul>';
    }
    $mmenu_output .= '</li>';
  }
  return '<ul class="mmenu-mm-list-level-' . $depth . '">' . $mmenu_output . '</ul>';
}