When you use link_path on line 183, 186 and 207 to build the links changes by other modules are not being utilized since they all alter the href element in the menu array. Please update to use href so that changes made by modules such as menu_firstchild stick.

Comments

Anonymous’s picture

How do I use href? When I look at the menutree object, I don't see it in there.

ryanwebpage’s picture

href is returned in the array from the menu_tree_all_data call. After a few attempts I realized that both the menu_tree_page_data and menu_tree_all_data needed to be utilized to get the result we were after. We were losing the active trail. For some reason the menu_tree_all_data does not have the active trail set properly. We came with a solution if you are interested?

Anonymous’s picture

I'm definitely interested :-)

Anonymous’s picture

Status: Active » Postponed (maintainer needs more info)
ryanwebpage’s picture

We modified _megamenu_get_menu_tree to return more data with the following changes

/**
 * Retrieve a menu and pre-style before theming
 *
 * This function currently removes all "hidden" items, which could be
 * handled in the single iteration of the theme function.  But, I forsee
 * a need for other prep work that might be simmplfied with this second function
 *
 * Will be used in the future to add/alter attributes prior to theming
 *
 * @param $menuname
 *    The name of the menu to extract
 *
 * @return
 *    The pre-styled menu tree
 */
function _megamenu_get_menu_tree($menuname) {
  $menutree = menu_tree_all_data($menuname);
  $menutree_page = menu_tree_page_data($menuname);
  
  foreach($menutree_page as $level1_key => $level1_item) {
		if ($level1_item['link']['in_active_trail']) {
			$menutree[$level1_key]['link']['in_active_trail'] = TRUE;
		}
		if ($link1_item['link']['hidden'] == 1) {
      unset($menutree[$link1_key]);
    }
    else {
			if ($level1_item['below']) {
				foreach($level1_item['below'] as $level2_key => $level2_item) {
					if ($level2_item['link']['in_active_trail']) {
						$menutree[$level1_key]['below'][$level2_key]['link']['in_active_trail'] = TRUE;
					}
					
					if ($level2_item['link']['hidden'] == 1) {
	        	unset($menutree[$level1_key]['below'][$level2_key]);
	        }
					else {
						if ($level2_item['below']) {
							foreach($level2_item['below'] as $level3_key => $level3_item) {
								if ($level3_item['link']['in_active_trail']) {
									$menutree[$level1_key]['below'][$level2_key]['below'][$level3_key]['link']['in_active_trail'] = TRUE;
								}
								
								if ($level3_item['link']['hidden'] ==1) {
		                unset($menutree[$level1_key]['below'][$level2_key]['below'][$level3_key]);
		            }
		            else if ($level3_item['below']){
                	unset($menutree[$level1_key]['below'][$level2_key]['below'][$level3_key]['below']);
            		}	
							} // end level 3 loop
						}
					}
				} // end level 2 loop
			}
		}
  } // end level 1 loop
  return $menutree;
}

We also updated your megamenu theme function to utilize drupals themable item list

/**
 * Theme a menu tree
 * 
 * This function takes a menu tree, such as primary links, and generates 
 * HTML markup of the menu so that it can be styled as a mega menu. It
 * takes the first three nested levels of the menu tree and creates a
 * structure of nested lists with appropriate classes and IDs assigned (even,
 * odd, active, etc.).
 *
 * First, we iterate through the first level of menu items (branch/tier-1/megamenu-bin). Each
 * item will be the megamenu-parent of the second level of links (twig/tier-2/megamenu-slot).
 * Next we iterate through the twigs of the menu tree to fill the megamenu-bins. A bin
 * is an unordered list which contains slots (twig/tier-2 items). To fill the slots we iterate
 * through each twig, where the leaves are the deepest level of the menu tree (tier-3). Each leaf
 * is a list item containing a tier-3 menu link.
 *
 * Abbreviations: t1, t2, & t3 stands for tier-1, tier-2, and tier-3
 * respectively. They represent nested level menu items.
 *
 * @param $menutree
 *    The menu tree to be marked up (i.e. primary_links)
 * @return
 *    HTML markup for a mega menu
 *
 */
function megamenu_theme_menu_tree($menu_name) {
  $menutree = _megamenu_get_menu_tree($menu_name);

  $skin = _megamenu_get_skin_by_name($menu_name);
  $menu_orientation = _megamenu_get_menu_orientation_by_name($menu_name);

  // TODO: Currently, these attributes are set menu wide. Eventually these might should be set per menu level?
  $slot_orientation = _megamenu_get_slot_orientation_by_name($menu_name); /* TODO: temp value, should be attached to branch level in admin interface */
  $slot_attributes = _megamenu_get_slot_attributes_by_name($menu_name); /* TODO: temp value, should be attached to twig level in admin interface. */


  $t1_position = 0;
  $branch_count = count($menutree);
  
  foreach ($menutree as $branch) {
  
    if ($branch['below']){
    
      $t2_position = 0;
      $twig_count = count($branch['below']);
      
      foreach ($branch['below'] as $twig) {
    		
        if ($twig['below']){
        
          $t3_position = 0;
          $leaf_count = count($twig['below']);
          foreach ($twig['below'] as $leaf) {
          
		    		// are we active / active-trail ?
		    		$active = _megamenu_active_classes($leaf);
				    $leaf_link_options['attributes'] = array('class'=>$active);
          	
            $t3_count_attributes = _megamenu_count_attributes($t3_position, $leaf_count);
            $t3_position++;
          	
          	$leaf_items[] = array(
          		'id'		=> 'megamenu-mlid-'.$leaf['link']['mlid'],
          		'class'	=> 'megamenu-item'.$t3_count_attributes.$active,
          		'data'	=> l($leaf['link']['link_title'], $leaf['link']['href'], $leaf_link_options)
          	);
          	
          } // END leaf iteration
          
          // Build leaf list
          $leaf_list_options = array(
          	'class'=> 'megamenu-items '.$slotattributes
          );
          $leaf_items_list = theme('item_list',$leaf_items, NULL, 'ul',$leaf_list_options);
          $leaf_items_list = _megamenu_strip_list_wrapper($leaf_items_list);
          unset($leaf_items);
          
        } // END leaf detection
        
        $t2_count_attributes = _megamenu_count_attributes($t2_position, $twig_count);
        $t2_position++;

    		// are we active / active-trail ?
    		$active = _megamenu_active_classes($twig);
				$link_options['attributes'] = array('class'=>$active);
				
				// This twig's <li> content
				$twig_data = '<h3 class="megamenu-slot-title">';
				$twig_data .= l($twig['link']['link_title'], $twig['link']['href'], $link_options);
				$twig_data .= '</h3>';
				$twig_data .= $leaf_items_list;
				
				$twig_items[] =	array(
					'id'		=> 'megamenu-mlid-'.$twig['link']['mlid'],
					'class' => 'megamenu-slot '.$t2_count_attributes.$active,
					'data'	=> $twig_data
				);
				unset($leaf_items_list);
      } // END twig iteration

      // Build twig list
      $twig_list_options = array(
      	'class' => 'megamenu-bin megamenu-slots-'.$slot_orientation
      );
      $twig_items_list = theme('item_list', $twig_items, NULL, 'ul', $twig_list_options);
      $twig_items_list = _megamenu_strip_list_wrapper($twig_items_list);
      unset($twig_items);
      
    }  // END twig detection
	

	  // setup active link classes
  	$active = _megamenu_active_classes($branch);
  	
  	// Link options
		$branch_link_options['attributes'] = array('class'=>$active);
		
  	// setup $t1_count_attributes (classes)
  	$t1_count_attributes = _megamenu_count_attributes($t1_position, $branch_count);
	  $t1_position++;  
  
    $branch_items[] = array(
    	'id' => 'megamenu-mlid-'.$branch['link']['mlid'],
    	'class' => 'megamenu-parent'.$t1_count_attributes.' menu-'.$branch['link']['mlid'].$active,
    	'data' =>  '<h2 class="megamenu-parent-title">'.l($branch['link']['link_title'], $branch['link']['href'], $branch_link_options).'</h2>'.$twig_items_list
    );
    unset($twig_items_list);

  } // END branch iteration
  
  // Build branch list
  $branch_list_options = array(
  	'id' 		=> 'megamenu-'.$menu_name,
  	'class' => 'megamenu-menu '.$menu_orientation .' megamenu-skin-'.$skin
  );
		
  $output = theme('item_list', $branch_items, NULL, 'ul', $branch_list_options);
  $output = _megamenu_strip_list_wrapper($output);
  unset($branch_items);
  
  return $output;
}

I believe my partner in crime electblake reached out to you already about being co-maintainers. Are you interested?

Anonymous’s picture

Yeah, have electblake submit this change as a patch in his co-maintainer request post.

Anonymous’s picture

Actually, post the patch in this thread and then point to it from the co-maintainer request.

erykmynn’s picture

I like this! Once we have a patch, we will put through the co-maintainer request!

electblake’s picture

StatusFileSize
new7.79 KB

EDIT: SORRY - I FORGOT AN ADDITIONAL FUNCTION I CREATED FOR THE LIST_ITEM UPDATE. _megamenu_active_classes RE-DIFFING SEE BELOW PATCH in COMMENT #10

As per Jepedo's note above - I created a patch for our updates. Please review and let us know.

Please note that we had (unknowningly) worked - http://drupal.org/node/800308 - into our code and our version will probably require updates to sync with that patch (sorry!)

electblake’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new9.12 KB

Sorry about that - it's been a couple of week since we last created these updates, forgot all that was required.

New Patch Attached.

lobo235’s picture

I just installed the patch from #10 without any errors during the patch process but now the module no longer works so I had to back it out. Here is the PHP error encountered after the patch:

[17-Sep-2010 10:48:46] PHP Fatal error:  Cannot redeclare _megamenu_is_skin_default() (previously declared in /Applications/MAMP/htdocs/aaml/sites/all/modules/megamenu-DRUPAL-6--1/megamenu.utilities.inc:96) in /Applications/MAMP/htdocs/aaml/sites/all/modules/megamenu-DRUPAL-6--1/megamenu.utilities.inc on line 230
ryanwebpage’s picture

StatusFileSize
new12.65 KB

Sorry about that. There was a duplicate function that ended up getting copied by mistake.

New patch attached

*** Edit ***
Sorry patch is incorrect. It was patched from the previous patch and not from the current version. I will upload a new patch

ryanwebpage’s picture

StatusFileSize
new10.71 KB

This should do it.

Anonymous’s picture

I just got around to testing this patch and it looks like things have changed a bit since the patch was generated. megamenu.utilities.inc patches cleanly, but megamenu.module fails at #169.

I think the addition of the CSS custom path pushed the code down a few lines, which is why this patch fails.

kansaj’s picture

HI it's working really nice, I would like to propose just to set additional class for items, which don't have submenu.

Fanaile’s picture

Hi;

I tried to apply the patch at #13; but I wasn't able to run update.php - it just kept bringing me to a blank screen. When I reverted back I could run update.php again.

Anonymous’s picture

Category: bug » feature
Anonymous’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Fixed

Commited change to use href instead of link_path to 6.x-2.x-dev in #488966

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.