I think megamenu is a very nice module and has a feature!
After looking at multiple issues in theme_megamenu_menu_tree() I decided to refactor the function, so it's now much easier to fix bugs or make enhancements without 3 levels of cut&paste (or even 4 levels - 886652)
By the way my implementation (together with _megamenu_get_menu_tree() change http://drupal.org/node/1198976#comment-4669450) makes number of menu levels unlimited.
I tried to include fixes for the following issues, please review.
#1198976: Warning: Invalid argument supplied for foreach() in i18nmenu_localize_tree() (line 114 of sites/all/m
#886652: Can I add an extra degree of depth/nesting to the megamenu?
#1078694: Mega menu doesn't allow query strings in menu paths
#1170472: let "nolink" be handled by "special menu items" module in order to allow compatibility with "menu_attributes" module
#1195348: megamenu omits link parameters
#1172776: Make MEGA only one menu item?
#865892: Menu items that are not links
#799280: Ability to inject custom css classes into each level of the menu - menu attributes compatibility
I couldn't include also the patch http://drupal.org/files/issues/0001-fix-1170472-use-theme_menu_link-to-r... as it's a bit too much for me ;) If @axel.rutz could have a look at my change and apply his patch?
I'm not setup for creating patches (yet), so I attach the file.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | megamenu-refactoring-1205068.patch | 16.15 KB | alexbk66- |
| #15 | megamenu.module.txt | 10.53 KB | alexbk66- |
| #15 | megamenu.utilities.inc_.txt | 6.05 KB | alexbk66- |
| #7 | megamenu_nochildren.png | 16.56 KB | alexbk66- |
| #7 | megamenu.module.txt | 10.2 KB | alexbk66- |
Comments
Comment #1
alexbk66- commentedAnd just in case, here's the function:
And a couple of helper functions:
Comment #2
alexbk66- commentedI added
$minimize_html = TRUE;as my taxonomy menu has 500 items, so by removing unused classes and attributes I reduce the html size significantly. I am going to make it configurable, but for now it should be changed to FALSE.Comment #3
alexbk66- commentedAnd I move here my refactored _megamenu_get_menu_tree() from #1198976: Warning: Invalid argument supplied for foreach() in i18nmenu_localize_tree() (line 114 of sites/all/m
Comment #4
alexbk66- commentedAnd I think that with the new theme_megamenu_menu_tree() implementation _megamenu_get_menu_tree() is no longer necessary, the check for active menu item can be easily moved to theme_megamenu_menu_tree_helper() or _megamenu_active_classes().
If maintainers of the module are interested in my changes, I can do this one also.
Comment #5
Anonymous (not verified) commentedThanks for your hard work on this. Eric or I will try to review this soon.
Comment #6
Anonymous (not verified) commentedComment #7
alexbk66- commentedI've split up the theme_megamenu_menu_tree_helper() function in smaller functions - I tried to implement #1172776: Make MEGA only one menu item?, but don't have time anymore.
I've got some hacky code there (commented with //HACK) which actually does work, but it's not nice. So if the items at second level don't have children - they are displayed as level 3 items, in single slot. Image attached.
I guess it's simpler to do that in _megamenu_get_menu_tree_helper() instead - if list of items doesn't have children - insert an extra level (single 'nolink' line) and move the list to this line children. Then the hack can be removed from theme_megamenu_menu_tree_helper().
And the file attached.
Comment #8
alexbk66- commentedHi there, how is review going? I think that original code is a bit too messy and before doing any fixes/enhancements it should be refactored. I spent already some time cleaning the code - using nested call instead of having 3 or 4 FOREACH levels. Would be nice if this code could be used.
Comment #9
Anonymous (not verified) commentedThanks for your hard work on this. If you don't mind taking a few extra steps it will make things much easier for us. First, download the coder module. Coder will assist you in cleaning up the code and ensuring it conforms with Drupal conventions. Second, please submit your modifications as a patch.
If you need help with making patches, let me know.
Comment #10
tami.allen commentedWould love to see the patch file for this. I need Main Menu items as placeholders. I'm using D7 with a subtheme of Marinelli and I'm unable to get to work even after applying the patch in http://drupal.org/node/1170472. I have installed/enabled the 7.x-1.x dev version of Mega Menu and Special Menu Items 7.x-1.0. When editing a menu item, the description says to use "nolink" but every time I try I get this error: "The path "nolink" is either invalid or you do not have access to it."
Is it possible for me to pull the nolink function from your .txt file (lines 238-253?)? If so, where do I paste it?
Comment #11
dipole commentedHi,
I would like to know if it's possible to add a class for parent items that do not have children in version 7. would appreciate any help.
Thanks in advance!
Comment #12
bomarmonk commentedThis looks like a great patch. Can someone run this through the coder module and submit it as a regular patch file? If I get a chance, maybe I'll give it a go!
Comment #13
sittard commented#3 works for me but you need to remove the following:
dsm($item[$tier_key]['below'], 'Removing');The dsm function requires Devel.
Comment #14
alexbk66- commentedYeah, this was just for debugging in case taxonomy has more than 3 levels
Comment #15
alexbk66- commentedI'm really sorry I didn't make a patch, I have to start learning patching. As my changes (refactoring) are pretty significant, I attached my version of two files, hope this helps to make this beautiful module even better!
I added .txt as drupal doesn't allow .module or .inc extensions.
Comment #16
alexbk66- commentedI finally learned how to create patches, well, not completely, see http://drupal.org/node/1054616#comment-5725064, help appreciated.
Here's the patch against 6.x-2.0-beta2 (I hope)
Comment #17
Anonymous (not verified) commentedComment #18
Anonymous (not verified) commentedComment #19
greggmarshallOnce I got past a problem applying the patch, the code that resulted worked perfectly!
Thank you for this.
Comment #20
alexbk66- commentedMy pleasure @greggmarshall, it's my first Drupal patch :)
Comment #21
oktay commentedAny word on if & when this will be incorporated into the official code?
Comment #22
Anonymous (not verified) commentedI haven't had time to give it a spin. Alexbk66, would you also take a stab at rolling the patch against the dev branch?
Comment #23
halloffame commentedThe patch only applied partially against 6.x-2.0-beta2. So decided to manually applied it but after doing so I can't still find the functionality/fixes I was expecting as mentioned in the original post.
Can anybody else please test the patch and report back?
Comment #24
ram4nd commentedLooks like this has been committed long time ago.