I am using the Megamenu on the Secondary Links menu. It returns the menu to me, but after the first set of links, the next root level parent item is nested inside of the first level of menu items in the preceeding UL.

Example:

Menu

Root Item 1
Root Item 2
--Child
--Child
--Child
------ Root Item 3
---Child

Etc etc. The 3rd Item should be outside of Item 2, not inside, as that is how my menu is structured.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chicagomom’s picture

I am suddenly experiencing this as well, though with 6.x-2.0-beta2. I am using the primary menu, and until last week it was working like a charm. I think it may be a conflict with another module, though I'm not sure.

It looks like extra "ul"s (with no css classes) are being added so items get pushed down the structure.

It looks like the classless ul being added are being added where a closing /ul tag should occur to close out a portion of the structure. So maybe the forward slash is somehow being excluded?

Edited to add: Yes, all closing /ul tags are having the forward slash removed. Anyone have ideas?

Anonymous’s picture

That's weird. I wonder what would cause that since we are building the lists using Drupal Core's theme item list.

chicagomom’s picture

I'm not sure either. Only does this if menu items are more than 1 level deep. When I have a moment I'll see if I can trace when this is happening, to see if I can isolate the cause.

For now, I'm just doing a replace on all the classless uls and making them into close ul tags. It's a hack, but it works. So at the end of the html coding process for the menu, on line 132 of megamenu.utilities.inc I've added this:

$output = str_replace('<ul>','</ul>',$output);

ClaudeS-1’s picture

I'm getting the same problem (via Marinelli theme version 7.x-3.0-beta9 - referred here via an issue there: http://drupal.org/node/1052762). Apologies if the source codes are different versions and thus not applicable.

I'm getting very invalid HTML generated because some of my 2nd level menu items don't have children.

I thought I'd give detailed examples, in case it's different to what people are experiencing, or if it helps debug.

It works perfectly if the top menu item has (level 2) children which all have (level 3)children - in this case, the level 2 children are in bold, and at the top of a column, with each of their (level 3) children in un-bold below.

However, if my (level 2) children have no (level 3) children, they appear in bold in one column, with this markup:

<li class="megamenu-li-first-level" id="menu-main-title-1163">
         <a href="/resources">Resources</a>
         <div class="mega four-col">
            <div class="megamenuWrapper">
               <ul class="megamenu-section">
                  <li class="menu-section-title" id="menu-section-title-1281">
                     <a href="/brochures">Brochures</a>
                     <ul class="megamenu-section">
                        <li class="menu-section-title" id="menu-section-title-1284">
                           <a href="/case-studies" class="active">Case Studies</a>
                           <ul class="megamenu-section">
                              <li class="menu-section-title" id="menu-section-title-1282">
                                 <a href="/product-datasheets">Product Datasheets</a>
                                 <ul class="megamenu-section">
                                    <li class="menu-section-title" id="menu-section-title-1283">
                                       <a href="/white-papers">White Papers</a>
            </div>
            <div class="closepanel">
               <span class="close-panel" title="close this panel">close this panel
               </span>
            </div>
         </div>
      </li>

Two errors here - firstly, the top div shouldn't have the class "mega four-col", as I want all 2nd level children to appear in one column.
And then, obviously, lots of ul items are being opened, never closed, with more ul items inserted.

This is what it should look like:

<li class="megamenu-li-first-level" id="menu-main-title-1163">
   <a href="/resources">Resources</a>
   <div class="mega one-col">
      <div class="megamenuWrapper">
         <ul class="megamenu-section">
            <li class="menu-leaf-list">
               <a href="/brochures">Brochures</a>
            </li>
            <li class="menu-leaf-list">
               <a href="/case-studies" class="active">Case Studies</a>
            </li>
            <li class="menu-leaf-list">
               <a href="/product-datasheets">Product Datasheets</a>
            </li>
            <li class="menu-leaf-list">
               <a href="/white-papers">White Papers</a>
            </li>
         </ul>
      </div>
      <div class="closepanel">
         <span class="close-panel" title="close this panel">close this panel
         </span>
      </div>
   </div>
</li>

I'm going to try to see if I can understand the code that generates this, but if anyone who's more familiar with the Marinelli Code, or Drupal's inner workings, can help, that would be greatly appreciated.

ClaudeS-1’s picture

FileSize
39.87 KB

I've had a play with the mega_menu function that I found in Marinelli Theme. Presuming it's similar enough to the latest dev build of Megamenu to be of use to people.

I've fixed the function enough to work as I want it to:

- it returns valid HTML, with all LI and UL tags closed
- if 2nd level items ALL have 3rd level items, then it will output the relevant class for column width ("two-col" if there are two 2nd-level items), and give each 2nd-level item a separate column.
- if one or more 2nd level items DON'T have children, then all 2nd-level items will appear in ONE column (with "one-col" class). ALL of these 2nd-level items will have their own UL tag, and the LI will have class "menu-section-title".
- the result (for me, at least) is that 2nd level items are always bold, and 3rd level items are always non-bold.

I've attached images showing the 3 possible results, and my code is shown below (my bracketing convention is different to the original).

I don't know if this can be used to patch/fix the Mega Menu project's bug, as I don't use the original module, and don't know about Drupal patches/fixes. Just trying to help :)

function subtheme_marinelli_mega_menu($variables)
{
   drupal_add_js(path_to_theme() . '/js/hoverintent/hoverintent.js');
   drupal_add_js(path_to_theme() . '/js/menu/marinelli_menu.js');

   $menu   = $variables['menu'];
   $alt    = theme_get_setting('menu_alt_class');
   $output = '<ul class="megamenu-1">'; // open list

   $count_main_links = 1;

   foreach ($menu as $key => $value)
   {
      if ($value['link']['hidden'] != 1)  // check if the link is hidden
      {
         $id = 'menu-main-title-' . $value['link']['mlid']; // give an unique id for better styling
         $options = array();
         if (isset($value['link']['options']['attributes']['title']))
         {
            $options = array('attributes' => array('title' => $value['link']['options']['attributes']['title']));
         }

         if (theme_get_setting('menu_headings') == 1) // first level markup (li or h2)
         {
            $output .= '<li class="megamenu-li-first-level" id="' . $id . '">' . l($value['link']['link_title'], $value['link']['href'], $options);
         }
         elseif (theme_get_setting('menu_headings') == 2)
         {
            // use <h2>, according to http://drupal.org/node/561750
            $output .= '<li class="megamenu-li-first-level" id="' . $id . '"><h2>' . l($value['link']['link_title'], $value['link']['href'], $options) . '</h2>';
         }

         $class = "";
         $altclass = "";

         if (in_array($count_main_links, $alt)) // add the alt class based on theme settings
         {
            $altclass = " alt";
         }

         $level2_items = count($value['below']);
         // start this value as number of level2_items, decrement each time a level2_item has children
         foreach($value['below'] as $level2_key => $level2_value)
         {
            if(count($level2_value['below']) > 0) // count number of level3_items
            {
               $level2_items--;
            }
         }
         if($level2_items == 0) // true when all level2_items have level3_children
         {
            switch (count($value['below'])) // choose mega class (div width based on the numbers of columns)
            {
               case 1:
               $class = 'one-col' . $altclass;
               break;
               case 2:
               $class = 'two-col' . $altclass;
               break;
               case 3:
               $class = 'three-col' . $altclass;
               break;
               case 4:
               $class = 'four-col' . $altclass;
               break;
               case 5:
               $class = 'five-col' . $altclass;
               break;
               case 6:
               $class = 'six-col' . $altclass;
               break;
            }
         }
         else
         {
            $class = 'one-col' . $altclass; // only want one column, as not every level2_item has children
         }

         if (count($value['below']) > 0 ) // check if we have children
         {
            $output .= '<div class="mega ' . $class . '">'; // open div mega
            $output .= '<div class="megamenuWrapper">'; // open div megamenuWrapper

            foreach ($value['below'] as $key2 => $value2)
            {
               if (count($value2['below']) > 0) // only if there are 3rd level children
               {
                  $output .= '<div class="menu-section">'; // open div menusection
               }

               $id = 'menu-section-title-' . $value2['link']['mlid']; // give an unique id for better styling
               $options = array('class' => array('menu-section-link'));
               if (isset($value2['link']['options']['attributes']['title']))
               {
                  $options['attributes'] = array('title' => $value2['link']['options']['attributes']['title']);
               }

               if (theme_get_setting('menu_headings') == 1) // && $value2['below']) { // use a list
               {
                  $output .= '<ul class="megamenu-section">'; // open section list

                  if ($value2['link']['hidden'] != 1) // check if the link is hidden
                  {
                     $output .= '<li class="menu-section-title" id="' . $id . '">' . l($value2['link']['link_title'], $value2['link']['href'], $options);
                  }
               }
               elseif (theme_get_setting('menu_headings') == 2) //  && $value2['below']) { // use <h3>
               {
                  if ($value2['link']['hidden'] != 1) // check if the link is hidden
                  {
                     $output .= '<h3>' . l($value2['link']['link_title'], $value2['link']['href'], $options) . '</h3>';
                  }
               }

               if (count($value2['below']) > 0) // only if there are 3rd level children
               {
                  $output .= '<ul class="megamenu-2">'; // open 2nd level list

                  foreach ($value2['below'] as $key3 => $value3)
                  {
                     $options = array('class' => array('menu-leaf-link'));
                     if (isset($value3['link']['options']['attributes']['title']))
                     {
                        $options['attributes'] = array('title' => $value3['link']['options']['attributes']['title']);
                     }

                     if ($value3['link']['hidden'] != 1) // check if the link is hidden
                     {
                        $output .= '<li class="menu-leaf-list">' . l($value3['link']['link_title'], $value3['link']['href'], $options) . '</li>'; // 2nd level <li>
                     }
                  } // end third foreach

                  $output .= '</ul>'; // close 2nd level <ul>
               }
               if (theme_get_setting('menu_headings') == 1) // close the list only if we use <li>
               {
                  $output .= '</li>'; // close 2ndlevel <li>
                  $output .= '</ul>'; // close section <ul>
               }

               if (count($value2['below']) > 0) // only if there are 3rd level children
               {
                  $output .= '</div>'; // close <div> menu-section
               }
            } // end second foreach

            $output .= '</div>'; // close <div> megamenuWrapper
            $output .= '<div class="closepanel"><span class="close-panel" title="close this panel">' . t('close this panel') . '</span></div>';
            $output .= '</div>'; // close <div> mega
         } // end check for children

         $output .= '</li>'; // close first level <li>
         $count_main_links++;
      } // end check if link is hidden
   } //end first foreach

   $output .= '</ul>'; // close first level <ul>

   return $output;
}
jeramy’s picture

Thank you, ClaudeS. This fix worked for me.
I am kind of surprised this hasn't been fixed in the Marinelli theme yet.

Using: Marinelli theme version 7.x-3.0-beta11

atodd’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
FileSize
108.48 KB

ClaudeS,

Thank you very much for this solution. Is there any way that you, or anyone else, could tell me which file to place this code in? Or do I need to create a new file? Any help would be greatly appreciated. The attached picture shows my current problem.

Using: Marinelli theme version 7.x-3.0-beta11

atodd’s picture

Category: bug » task
Priority: Normal » Major
Status: Active » Needs review

Can anyone help me out here? I would like to know where to put the code that ClaudeS posted above. Does it need to be added to an existing file or do I need to create a new file? If it goes in an existing file, which one? Which lines do I replace if any? If anyone can help I would be greatly appreciative.

Using: Marinelli theme version 7.x-3.0-beta11

atodd’s picture

Category: task » bug

Ok so, for anyone who wants to know, I figured out where the code needs to go:

sites/all/themes/marinelli/theme/theme.inc

I replaced the code that is already there and my menu disappeared completely. So I changed the first line from "function subtheme_marinelli_mega_menu($variables)" to "function marinelli_mega_menu($variables)" and that made the menu show up again but the menu still was not showing up in multiple columns. So I am currently going through the code, line by line, to try to get it working. All of my second level items have at least two third level items so I don't know why it's not working.

If anyone has any insight on this please let me know. I would be greatly appreciative.

Using: Marinelli theme version 7.x-3.0-beta11

Anonymous’s picture

Assigned: Unassigned »
Issue tags: +lowhanging, +review
thesuperav’s picture

FileSize
9.49 KB

I'm also using Marinelli 7.x-3.0-beta11 and encountered the same error. I've patched my theme.inc (attached - rename to theme.inc) and it works fine for me. You could do a diff, but the changes start from line 168 to line 221.