You are here

function template_preprocess_tb_megamenu_item in The Better Mega Menu 7

Same name and namespace in other branches
  1. 8 tb_megamenu.module \template_preprocess_tb_megamenu_item()
  2. 2.x tb_megamenu.module \template_preprocess_tb_megamenu_item()
1 string reference to 'template_preprocess_tb_megamenu_item'
tb_megamenu_theme in ./tb_megamenu.module
Implements hook_theme().

File

./tb_megamenu.themes.inc, line 83

Code

function template_preprocess_tb_megamenu_item(&$vars) {
  $level = $vars['level'];
  $item = $vars['item'];
  $mlid = $item['link']['mlid'];
  $trail = $vars['trail'];
  $link_attributes = array();
  $menu_config = $vars['menu_config'];
  $item_config = isset($menu_config[$mlid]['item_config']) ? $menu_config[$mlid]['item_config'] : array();
  tb_megamenu_edit_item_config($item_config);
  $vars['item_config'] = $item_config;
  if (!empty($menu_config[$mlid]['rows_content']) && ($vars['section'] == 'backend' || !$item_config['hidesub'])) {
    $vars['submenu'] = theme('tb_megamenu_submenu', array(
      'menu_name' => $vars['menu_name'],
      'parent' => $item,
      'level' => $level,
      'menu_config' => $vars['menu_config'],
      'block_config' => $vars['block_config'],
      'trail' => $vars['trail'],
      'section' => $vars['section'],
    ));
  }
  else {
    $vars['submenu'] = NULL;
  }
  $vars['classes_array'][] = 'level-' . $level;
  $vars['classes_array'][] = 'mega';
  if (!empty($item_config['class'])) {
    $vars['classes_array'][] = $item_config['class'];
  }
  if (!empty($item_config['alignsub'])) {
    $vars['classes_array'][] = "mega-align-" . $item_config['alignsub'];
  }
  if ($item_config['hidewcol']) {
    $vars['classes_array'][] = "sub-hidden-collapse";
  }
  if ($item_config['group'] && $vars['submenu']) {
    $vars['classes_array'][] = "mega-group";
    $link_attributes['class'][] = 'mega-group-title';
  }
  elseif ($vars['submenu'] && !$item_config['hidesub']) {
    $link_attributes['class'][] = 'dropdown-toggle';
    if ($level == 1) {
      $vars['classes_array'][] = 'dropdown';
    }
    else {
      $vars['classes_array'][] = 'dropdown-submenu';
    }
  }
  $vars['item']['link']['#attributes'] = $link_attributes;
  if (!empty($item['link']['localized_options']['attributes'])) {
    if (!(isset($item['link']['localized_options']['attributes']['title']) && $item['link']['localized_options']['attributes']['title'])) {
      $item['link']['localized_options']['attributes']['title'] = $item['link']['title'];
    }
    $vars['item']['link']['#attributes'] += $item['link']['localized_options']['attributes'];
  }

  // Ensure the link options are not NULL and an array.
  $vars['item']['link']['options'] = isset($vars['item']['link']['options']) && is_array($vars['item']['link']['options']) ? $vars['item']['link']['options'] : [];
  if (isset($trail[$mlid])) {
    $vars['classes_array'][] = 'active';
    $vars['classes_array'][] = $vars['a_classes'][] = 'active-trail';
  }

  // Add list item attributes.
  if (!empty($item['link']['localized_options']['item_attributes']['class'])) {
    $vars['classes_array'][] = $item['link']['localized_options']['item_attributes']['class'];
  }
  $vars['attributes_array']['data-id'] = $mlid;
  $vars['attributes_array']['data-level'] = $level;
  $vars['attributes_array']['data-type'] = 'menu_item';
  $vars['attributes_array']['data-class'] = $item_config['class'];
  $vars['attributes_array']['data-xicon'] = $item_config['xicon'];
  $vars['attributes_array']['data-caption'] = $item_config['caption'];
  $vars['attributes_array']['data-alignsub'] = $item_config['alignsub'];
  $vars['attributes_array']['data-group'] = $item_config['group'];
  $vars['attributes_array']['data-hidewcol'] = $item_config['hidewcol'];
  $vars['attributes_array']['data-hidesub'] = $item_config['hidesub'];
  if ($vars['section'] == 'backend') {
    $vars['attributes_array']['title'] = t("Menu Item");
  }
  if (!empty($item['link']['localized_options']['item_attributes'])) {

    // Add additional list item attributes besides the class (which was handled separately above).
    $vars['attributes_array'] += array_diff_key($item['link']['localized_options']['item_attributes'], array(
      'class' => NULL,
    ));
  }
}