Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
How are people expanding links for instance in a sidebar? Let´s say I click a menu item in the navbar and I want to add the menu to a sidebar and expand all sibling menu items but have parent items collapsed.
There are discussion in the queue about what should be default and what not but I can´t find any suggestions on how to do this.
I´m using menu block without success because everything is collapsed by default, no matter how I fiddle with the settings in menu block. I guess Bootstrap overrides it.
Comments
Comment #1
busla CreditAttribution: busla commentedAfter playing with the menu_tree and menu_link hooks I´ve been able to change the collapse functionality somewhat but can´t get the the desired functionality to work.
Here are some examples from what I want to happen on my sidebar:
http://bootply.com/61710
http://jsfiddle.net/luismruiz/YRVev/
These are two fundamentally different methods, one is using accordion and the other a custom js script. Another way to accomplish this would be to use the menu collapse functionality in a mobile view.
I would appreciate if someone could post a suggestion on how to override the template hooks mentioned above.
Thanks.
Comment #2
busla CreditAttribution: busla commentedOk, this took a while but I have found a solution that I´m very happy with (see theme_menu_link override below).
#Issue
My original issue was with horizontal menus on sidebars on pages that are visited. I also wanted an active trail to the page in the menu tree. I also wanted the menu tree to expand/collapse nicely using javascript, like so: http://bootply.com/63956
#Solution
I decided to use the Menu Block module since it offers setting configuration in the UI and some nice hooks to alter any menu on the sidebar. I´m also using Special Menu Items to create parent menu items since Bootstrap has a click dropdown menu instead of hover (which I like very much).
By using the theme_menu_link__[menu name] hook I altered the Bootstrap menu wrapper and added the neccesary classes required by the javascript.
The javascript didn´t want any text to be wrapped with tag that is applied by Special Menu Items so I needed to remove the tag before dumping the output to the l(); function (see the if statement at the end).
This is the altered code originally taken from the bootstrap_menu_link() function in includes/theme.inc
------
Comment #3
busla CreditAttribution: busla commentedOk, you can obviously just remove the nesting condition if you like since it makes no sense now :-)
Comment #4
busla CreditAttribution: busla commentedI still haven´t figured out why all parent menu items expand all children by default so if anyone wants to help out it would be appreciated :-)
Comment #5
busla CreditAttribution: busla commentedoops.. posted the wrong link to the javascript code i´m using. They seem to be the same except the class names are different.
http://cssdeck.com/labs/twitter-bootstrap-plain-collapsible-tree-menu
Comment #6
geresy CreditAttribution: geresy commentedThank you very much busla !
Took me a few good hours of trying on my own until i found your solution ! #2 works like a charm combined with the module Menu Firstchild.
Comment #7
busla CreditAttribution: busla commentedMenu Firstchild, guess I have to check out that module!
Thanks for posting :-)
Comment #8
markhalliwellThis issue has been closed while cleaning up the issue queue. The 7.x-2.x branch currently only receives security fixes.