Problem/Motivation
hook_menu_tree()
is used to generate the menu of navbar.
That means a custom hook menu tree definition in a theme may remove the default .menu
class from all menu trees including the navbar. In case of navbar the toolbar stops working in this case.
This example clashes already with bartik_menu_tree()
that adds .menu .clearfix
to navbar menu tree. For the reason that the .clearfix
class is added by bartik some things in navbar required wonky CSS overrides to get the clearfix issues pushed out. This wonky overrides hurts us in uncountable many cases and we will always need to add more workarounds if we do not solve the menu_tree root cause.
Proposed resolution
Add a navbar_menu_tree()
theming function and add our own menu class to navbar menus e.g. '<ul class="navbar-menu">' . $variables['tree'] . '</ul>';
. This way we stop injecting .menu
and .clearfix
class and get all a lot leaner and more reliable CSS code. As we no longer rely on standard hook_menu_tree the navbar no longer clashes with theme CSS and this will start working with all contrib themes. If a theme maintainer like to override he could do, too as there is a navbar specific theme function and not only one global that affects all menus.
Remaining tasks
Review and commit
User interface changes
None.
API changes
None.
Original report by hass
See attached screenshot that shows one of the typical bugs.
Comment | File | Size | Author |
---|---|---|---|
#21 | Issue-2119989-by-hass-Add-navbar_menu_tree-to-prevent-theme_clashes-D7.patch | 13.29 KB | hass |
Comments
Comment #1
hass CreditAttribution: hass commentedComment #2
hass CreditAttribution: hass commentedMy custom theme is injecting again my custom class and not
.menu
.This is the known menu_tree theming issue again. We really need to fix this!!! Suxxx
Comment #3
hass CreditAttribution: hass commentedIt's a bit different here. I have no chance to override this class here as there is no
hook_menu_tree__shortcuts
. No idea how to solve correctly.Comment #4
hass CreditAttribution: hass commentedThat is Drupal theme_tree hell...
shortcut_set_1
is a name that can be configured by users. That's really a joke.Comment #5
jwilson3I'm sorry, but I don't really understand any of the comments and how they relate to the image in the issue summary.
@Hass: Could you make this any easier to understand, by updating the issue summary to our standard format?
Also, what is the "known menu_tree theming issue" to which you refer, is there a link to that issue?
Comment #6
jwilson3Are you implying that this is something that would be resolved by #1777332: Replace theme_menu_link() and menu-tree.html.twig with a single Twig template?
Comment #7
hass CreditAttribution: hass commented#1944572: Remove "ul.menu" dependency to prevent theme clashes
Comment #8
jessebeach CreditAttribution: jessebeach commented#1898464: toolbar.module - Convert theme_ functions to Twig is close to being complete. It needs some guiding so that we can put this
.menu
issue to rest once and for all.Comment #9
jessebeach CreditAttribution: jessebeach commentedhass, could you include a small CSS file in your theme for Navbar as a library and add the library if the Navbar module is enabled? I hate to make this kind of soft dependency in your theme, but it seems as if you've got some advanced theme layer manipulation in your code and I'd like to see find resolution to this family of issues with menu trees.
Comment #10
hass CreditAttribution: hass commentedThe root cause of this issue is
.menu
class again. We need to remove this from the module and toolbar module, too. It's really the only option we have to make this rocket stable. Otherwise navbar will fail in every theme that override menu_tree what it already an issue in core, too.It looks like I'm just not a good candidate for writing the patch for this... :-(
Comment #11
jessebeach CreditAttribution: jessebeach commentedThis issue is really bothering me, too, and I have yet to come up with a way around it.
There must be a way to avoid that theme function altogether in Navbar and just use a custom list theme function.
Comment #12
hass CreditAttribution: hass commentedThis is one if not the highest prio case that need to be fixed.
Comment #13
alibama CreditAttribution: alibama commentedI'm using openframework from stanford that also seems to have some bootstrap in it - I'm seeing similar failure, reverted to admin menu. Really like navbar, look forward to seeing a functional release
Comment #14
meecect CreditAttribution: meecect commentedMy issue was closed as a duplicate of this ( https://www.drupal.org/node/2238133 ). I have a css snippet that one could use in your theme to solve the issue for at least me, using bootstrap and the navbar shortcuts menu. Basically, I just added this:
It gets the job done. If you know anything about the history of Drupal, waiting around for a cleaner and more official fix may take years.
Comment #15
hass CreditAttribution: hass commentedComment #16
hass CreditAttribution: hass commentedComment #17
hass CreditAttribution: hass commentedComment #18
hass CreditAttribution: hass commentedComment #19
hass CreditAttribution: hass commentedHere is the patch that works perfectly fine and solves all the many many issues and I think it fixes a lot of other open issues.
We can cleanup the CSS files from useless overrides in a follow up case. It would over-complicate this case otherwise I think.
Comment #20
hass CreditAttribution: hass commentedComment #21
hass CreditAttribution: hass commentedWhen I ported this code to D8 I found a theme override solution and ported these back to D7 now. It requires a lot less code and is easier to review. Let's go with this one.
Comment #22
hass CreditAttribution: hass commentedComment #23
eshta CreditAttribution: eshta commented@hass - this approach is great. Much cleaner. I'm going to test it out locally on a few things before I RTBC it. I encourage any other folks following this issue to give it a spin and add some feedback.
Comment #24
eshta CreditAttribution: eshta commentedComment #25
hass CreditAttribution: hass commentedWill you commit this? :-)
Comment #26
eshta CreditAttribution: eshta commentedYup... Just about to :-)
Was running through the list of items to get a sense of everything going in.
Comment #28
eshta CreditAttribution: eshta commentedComment #29
hass CreditAttribution: hass commentedGreat. Let's try to get #2227293: Remove navbar from print view done before a new release so we may be done for a very long time.
Comment #30
claudiu.cristeaFollowup bug #2404801: Shortcut table used, but Shortcut module may be disabled.
Comment #31
hass CreditAttribution: hass commentedFollow up bug #2403649: Menu items in RTL not properly aligned
Comment #32
hass CreditAttribution: hass commentedPlease also help getting the D8 patch in core.