Fix for expanded menu overide for set MID - needs to collapse MID properly when not ative

  1. /**
  2. * Implementation of theme_menu_item().
  3. * Add active class and custom id to current menu item links.
  4. */
  5. function zen_menu_item($mid, $children = '', $leaf = TRUE) {
  6.   // store a list of the menu items that are products
  7.   // use a static var so we only do this once.
  8.   static $products = null;
  9.   if (!$products) {
  10.     $products= array();
  11.     $products_mid = 109;
  12.     $products_item = menu_get_item($products_mid);
  13.     $products[$products_mid] = $products_item['path'];
  14.     foreach ($products_item['children'] as $child_mid) {
  15.      $child = menu_get_item($child_mid);
  16.      // we want the paths because we have to check to see if one of them is active
  17.      $products[$child_mid] = $child['path'];
  18.     }
  19.   }
  20.  
  21.   $item = menu_get_item($mid); // get current menu item
  22.   // decide whether to add the active class to this menu item
  23.   if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path...
  24.   || (drupal_is_front_page() && $item['path'] == '<front>')) { // or front page...
  25.     $active_class = ' active'; // set active class
  26.   } else { // otherwise...
  27.     $active_class = ''; // do nothing
  28.   }
  29.  
  30.  
  31. // we only expand the products menu on the front page
  32. // or when a product is selected.
  33. // there is a special kind of action when we are on the product page itself.
  34.   $is_product = in_array($_GET['q'], $products);
  35.  
  36.  
  37. if (!$children || (!$is_product && !drupal_is_front_page() && $mid == 109) )
  38. {
  39.   $is_expanded = false;
  40. }
  41. else
  42. {
  43.   $is_expanded = true;
  44. }
  45.   $attribs = isset($item['description']) ?
  46. array('title' => $item['description']) : array();
  47.   $replace = array(' ', '&');
  48.   $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));
  49.   return
  50. '
  51. <li class="'. ($leaf ? 'leaf' : ($is_expanded ? 'expanded' : 'collapsed')) .
  52. $active_class .'" id="'. $attribs['id'] . '">' .
  53. menu_item_link($mid) . $children ."</li>
  54. \n";
  55. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.