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.
Problem/Motivation
The current 2nd level horizontal menu takes only the width of the parent, and if a bg other than transparent is set, this is clearly visible.
Steps to reproduce
Display the 2nd level horizontal menu on hover.
Proposed resolution
In navbar.js we already add .second-level-show to the .navbar-wrapper, but we currently don't have any styles for it.
Opposite of the -expanded version, we here position the 2nd level menu absolutely. Therefore we can drop the position relative definition and padding and just display the after element for both options.
Comment | File | Size | Author |
---|---|---|---|
#12 | 3187654-expand-2nd-level-12.patch | 14.32 KB | pivica |
Comments
Comment #2
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedHere is the patch with the proposed solution.
Comment #3
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedNeeded to fix the z-index display so that the 2nd level overlaps the hero image and the content below it.
Comment #4
pivica CreditAttribution: pivica at MD Systems GmbH commentedBased on discussion with @Berdid, @sasanikolic and @jzech here is a new patch. I've added a new theme option 'Overlay second level' with the next values:
'Off' option is a default one and this is how second-level horizontal menu was behaving for now. The 'When not active' option is the one we discussed. Then adding 'Always' overlay option was my addition.
Comment #5
pivica CreditAttribution: pivica at MD Systems GmbH commentedFound some additional problems, actually cases that are not well covered. I think this is connected with changes in \Drupal\system\Plugin\Block\SystemMenuBlock::build() so reapplied those changes here.
Also, we do not need any more `$navbar-2nd-menu-bg`, it is replaced with newly introduced `$navbar-2nd-bg`, so we can remove it.
Comment #6
pivica CreditAttribution: pivica at MD Systems GmbH commentedCopy&pasting that code from `SystemMenuBlock::build()` is maybe a bad thing? If something changes again later it can hit us here. Also, code is becoming bigger and more complex in `bs_bootstrap_preprocess_page()`. Howe about we maybe just call that `SystemMenuBlock::build()` method instead of duplicating that code? Here is a patch that does that, seems it works fine.
Comment #7
pivica CreditAttribution: pivica at MD Systems GmbH commentedFound some additional layout problems when both first and second levels have bottom borders.
Comment #8
pivica CreditAttribution: pivica at MD Systems GmbH commentedDamn, found one more, we do not need `$configuration['expand_all_items']` any more (from previous refactorings) and it is not needed any more, plus it creates problems. Removed it.
Comment #9
pivica CreditAttribution: pivica at MD Systems GmbH commentedThe last patch got uploaded wrong somehow, here is a correct one.
Comment #10
Berdir$plugin is exactyl the same thing as $menu_block, you don't need to create that, you already have an instance of that block with the correct configuration.
Note that you must never instantiate a plugin like that manually, always use the plugin manager service, because those arguments might change over time.
FWIW, the overall approach isn't great for performance, because we have to load, process and prepare the menu twice, and this runs even if the blocks themself are render cached. But I don't really have an idea to handle that better.
Also, the get base id check isn't perfect, it's possible that custom block plugins are used for this, we have projects like that (which then dynamically decide on the menu to display), but sadly there is no way to detect a block that will render a menu any other way I think.
At most we could make the plugin id(s) configurable, but we can consider that when we need that.
Comment #11
pivica CreditAttribution: pivica at MD Systems GmbH commented@berdir thank you for your review, here is a new patch based on your comment. Tested everything one more time, seems it is working OK.
Comment #12
pivica CreditAttribution: pivica at MD Systems GmbH commentedThe latest patch needed a small change because we removed the lazy loading option in favour of core handling this.
Comment #14
pivica CreditAttribution: pivica at MD Systems GmbH commentedCommitted.
Comment #15
pivica CreditAttribution: pivica at MD Systems GmbH commented