Problem/Motivation
Version 6.x-2.2 of Menu Block module had a key feature that would fallback to showing items on the current level (i.e. siblings to the active menu item) when the active menu item doesn't have any children.
Neither Drupal 7 nor Drupal 8/9 versions of the Menu Block module have this feature.
This is a very common use case for creating a sidebar secondary nav that is only ever supposed to be one or two levels deep at any given time, but is setup to always show as much relevant information as possible.
Steps to reproduce
If a menu block is configured to:
- show 1 level,
- follow the active menu item,
- set the initial visibility rule to show Children of active menu item.
then when the user clicks on any child link, the menu display is less than helpful and only contains a single item (the current page).
Proposed resolution
Add a third option to the "Initial visibility level" radios:
- Active menu item
- Children of active menu item
- New option: Children of active menu item; active menu item if no children
Remaining tasks
User interface changes
Users will see a new option in the menu block configuration screen.
API changes
The follow_parent menu block setting variable will respond to a new option called child_or_active in code.
Data model changes
N/a
| Comment | File | Size | Author |
|---|
Issue fork menu_block-758184
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
emdalton commentedDid this get disabled in 6.x-2.3? We upgraded due to teh XSS issue, and all of a sudden our sidebar menus all vanished beyond the first level. We used to be able to see same-level items on pages with no children. For now, we're going to have to go back to an earlier version-- I can't go through and rebuild all our menus!
Comment #2
johnalbinIt sounds like you were wanting the behaviour that others thought was a bug. Is that correct? #345552: Inconsistent display of starting level set to children of active item
Comment #3
temp commentedYes, and i will be happy if this being optionally switchable in new version.
Comment #4
Andreas Stenberg commentedI double that!
Comment #5
emdalton commentedYes, exactly.
Comment #6
merovian commentedHere's the solution for this problem that works for me -- I found the difference in the file menu_block.follow.inc between ver 6.2.2 and 6.2.3
Just remove these lines 53 - 55 from the file menu_block.follow.inc:
I can't remember how to write a patch file otherwise I would. Anyway, here's how I got this to work for my site.
Comment #7
temp commentedthe best option would be an optional switch
Comment #8
pennykara commentedI second the optional switch, as it creates more consistency and thus improves user experience.
Comment #9
markhalliwellI doubt this is the same issue, but I figured I'd share my idea with others that might encounter my issue. For me, if a top level menu item doesn't have any children the entire block doesn't show. Blocks need content, this is just how they work.
My menu block titles are all linked and I still need the block to show so you can click on the title regardless if you have no children. I use fgMenus on my site (http://www.juneauschools.org) to dynamically generate menus based on what
clocksblocks are present in my menu region.So I decided to modify menu_block a little to check and see if the content (menu) is empty and replace it with a UL tag with a class of "nomenu". I've also included my little recursive jQuery script that dynamically goes through each menu block and skips the "ul.nomenu" ones. Enjoy!
It would be nice if the title could always be shown or at least give the option, like they've said above.
and jQuery:
2010-06-08: Edited
Comment #10
markhalliwellJust realized that I should probably upload the fgMenu JavaScript if have seriously modified. I have fixed a lot of bugs and added a new feature (themes). Please contact me if you have any questions.
Comment #11
theunraveler commentedHere's a simple patch for the change suggested in #6. I agree that this should be an option, but I don't have time to write the functionality.
Comment #12
emdalton commentedSo if I update to 6.2.3 and apply this patch, will I be able to see sibling menu items? What happens if another version of MenuBlock comes out?
Comment #13
emdalton commentedHas this patch been rolled in to dev yet?
Comment #14
temp commentedAnd little extension of my feathure request,
if i disable all child of some parent menu item - menu block module (and core menu module) process them as simple child items - but if i go to this parent-child level, same level items don't showing. path above can't solve this problem (but perfectly working with simple child items), please add optionaly support of parent-child items. Thanks!
Comment #15
Renee S commentedI support making this an option - I'm the person who filed the original "no children, don't show siblings either" issue (and still need it that way in some circumstances) - but now I'm working on a site with a different architecture, and have found a compelling use-case for the "show siblings" scenario myself.
I think there are good reasons to make this functionality selectable and transparent, and there's clearly a need for both!
@emdalton If you apply this patch it will get written over by the next version. I don't think it's the best idea to apply it unless you've got a good maintenance log or something, or your site will break. Making it an option with the default behaviour being the current way (no menu) would stop other sites from breaking on upgrade but allow us to use the new functionality going forward if we need it.
Comment #16
emdalton commentedStill not rolled into the current version? :( I'll apply the patch again, but I really would like to see this changed for future releases. Is a bounty needed?
Comment #17
tangent commentedI required the ability to show a menu block of "sibling menus" for some pages as well. I was able to achieve this, without patching, with the following method.
1. Create 2 menu blocks, identical.
2. For the menu block that should show siblings, instead of children, set "Starting level" to "Active menu item"
3. Check "Expand all children"
4. Set "Maximum depth" to 1 (unless you want the whole tree)
5. Optionally use some PHPfoo in the block configuration to alternate showing the appropriate menu block.
Comment #18
arbel commentedHi,
I needed to display a menu block even if there are no children -> display only the title which is set as a link.
I had to hack the module:
I simply commented out the check if there is no content, and it works great.
Is it possible to add this as an option to the block config - "[] Display menu block even if there are no menu items" so something along those lines.
Thanks
Idan
Comment #19
tangent commented@arbel, yours is a separate issue. You should create a new issue for it.
Comment #20
arbel commentedoh..ok thought this was the same use case.
Comment #21
bak commentedSubscribe.
The "[] Display menu block even if there are no menu items" option is needed.
Without #18 hack I saw "Notice: Trying to get property of non-object in theme_blockreference_formatter_title() (line 683 of /sites/all/modules/blockreference/blockreference.module)." when I was creating a view with Menu Blocks for menus without children.
Comment #22
cabplan commentedI tried to use #18 hack and nothing changed with my nav menu that had no children, it still shows it as blank when I want it to remain as the same nav, if there are no children
Comment #23
dave reidComment #24
lukasss commentedThis patch (#11) works for me ( version 7.x-2.3), thanks you
Comment #25
nelec commentedHi.. I am dealing with the same issue, namley "Ability show items on same level if active menu level don't have children"
but working on a subsite I can't directly patch the Block Menu module.
Does anyone know an alternative to get the same result?
I thought about working on the subtheme template or adding php conditions to the block, but don't have any idea of where to start from..
Comment #26
zerolab commentedAttaching a patch against latest 7.x-2.x
This augments #11 with a new
follow_parentoption, rather than removing the current functionality that follows the children.Cheers,
Dan
Comment #27
jojonaloha commentedWe've been using #11 for over a year. I just tested #26 and it works as expected and I think is better for backwards compatibility.
For anybody using #11, if you switch to #26, you'll need to update your menu blocks config to maintain this behavior. I used an update script in a custom module:
Comment #28
gmclelland commentedThis seems very similar to the patch posted at #1620298: Add new starting level option "Children of active menu item, and active menu item if no children". Can anybody confirm or explain the differences?
Comment #29
jojonaloha commentedI've looked at both patches #758184-26: Show items on same level if active menu level doesn't have children and #1620298-1: Add new starting level option "Children of active menu item, and active menu item if no children" and can confirm that they should be functionally identical (although I did not test the patch in the other issue). The only differences appear to be:
Comment #30
jwilson3In addition to #29 there were actually two other issues (now linked via reference in the sidebar) that provided patches that effectively do the same thing as this issue. I've closed all those as duplicates and will update this to the Drupal 8 version, and provide a patch.
For anyone still looking for the "best" patch for Drupal 7, #26 is probably your best shot.
Here is a Drupal 8 version that uses the underlying field value from #26 but the wording from #1620298-1: Add new starting level option "Children of active menu item, and active menu item if no children", which seems more inline with the field value and doesn't mention siblings, because a given active link may or may not have siblings.
Comment #31
jwilson3There is a syntax error in the last patch.
Comment #32
ac#31 works
Comment #33
acComment #34
jwilson3Cleaned up issue title and summary
Comment #35
nvakenThis patch seems to work fine for us.
Comment #36
joelpittetComment #37
kevinquillen commentedBig addition indeed. Helps keep the menu from just vanishing.
Comment #38
kevinquillen commentedIn addition - is there a way to prevent this behavior IF the item is level 0 and has no children? I don't want to show the top level navigation in that case.
Comment #39
nvakenYou might just be better off creating a second menu block in the same spot that only shows the root items if on that level? I think it might be a bit feature creep to implement those edge cases?
Comment #40
joelpittetComment #41
joelpittetRan out of time to test and commit this so moving to the next release
Comment #42
daniel korteReroll
Comment #45
greenskin commentedWe have a need for this feature. Additionally we needed the title/label to reflect similarly, where it displays the active item's title when it has children otherwise it displays the parent's title. This patch is a re-roll of #42 with a new block label option that will use the active item's title when the item has children, otherwise uses the parent title.
Comment #46
marthinal commentedReroll
Comment #47
joelpittet@greenskin, it looks like you merged stuff from a different issue which conflates this issue, I feel like I have seen that elsewhere but haven't been able to spot it. Can someone ensure this is working with what the issue summary suggests on MR21 please?
I am hiding the patches as I would prefer an Merge Request.
Comment #49
daniel korteApologies for the noise. I tried to fix the merge request, but it did not go well so I created a new branch that is now mergeable.
Comment #50
jwilson3I can confirm the MR #36 is a faithful reroll of the patch in #42 (without the extraneous code added in #45 and #46).
Thanks for the work @danielkorte
Comment #53
fabiansierra5191 commentedI can confirm the MR #36 works as well, and it's a good feature for the module.