Currently, menu_fields replaces the 'menu_link' theme function altogether. This is kind of extreme and will undo any styling that the theme was doing to the top-level <li ...></li>
tag and the primary link.
For example, in a Bootstrap-based theme, it'll add a number of classes and data-* attributes to the <li ...></li>
tag to turn the menu link into a dropdown, and add a 'caret' icon to the text of the primary link.
Because menu_fields replaces the 'menu_link' theme function completely, all these customizations are lost, AND the only way to add them back is to alter the theme registry, removing menu_fields_link()
and redoing most of the code in that function. :-/
Proposal
Instead of replacing the 'menu_link' theme function entirely, use hook_preprocess_menu_link()
to render the menu fields and use them to replace $vars['element']['#below']
. This way the theme is still reponsible for rendering the menu link its normal way.
This has a couple of cool side benefits:
- In Bootstrap-based themes, it's probably already rendering the children of the main menu as a dropdown, so menu_fields will just work!
- This fixes #2460187: menu_fields_theme_registry_menu_link will be wrong if there are multiple themes because we no longer need to try and store the original 'menu_link' theme function
I'll post a proof-of-concept patch soon-ish...
Comment | File | Size | Author |
---|---|---|---|
#3 | interdiff.txt | 316 bytes | dsnopek |
#3 | menu_fields-preprocess-menu-link-2460201-3.patch | 2.39 KB | dsnopek |
Comments
Comment #1
dsnopekComment #2
dsnopekPatch is attached! Please let me know what you think. :-)
Comment #3
dsnopekHere's a new version of this patch that also adds a class to menu links that have content added by menu_fields. This can be useful for styling mega menus different than normal dropdowns in your theme.
Comment #5
donutdan4114 CreditAttribution: donutdan4114 commentedThanks!
Comment #6
dsnopekWoohoo! Thanks for the quick commit! :-)