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.
When using current level as the top level, please add an option to hide siblings of the current level.
Given a tree:
Item 1
Item 1.1
Item 1.1.1
Item 1.1.2
Item 1.2
When viewing contents of 1.1, the Item 1.2 should be hidden using that option.
Comment | File | Size | Author |
---|---|---|---|
#21 | hide_siblings-1390526-21.diff | 5.16 KB | heshanlk |
#14 | menu_block-stop-hiding-siblings-depth-1390526-13-7.x-3.x.patch | 5.55 KB | focal55 |
Comments
Comment #1
adamdicarlo CreditAttribution: adamdicarlo commentedDuplicate of #927380: Show only children of active item
Comment #2
Rob230 CreditAttribution: Rob230 commentedIt's not a duplicate of that. Hiding the siblings is different to hiding the children of siblings.
For example, I need to be have a menu tree like this:
Hiding the children of siblings would result in this:
Hiding the siblings would result in this:
I can't see any option to achieve this. If you want your menu to show Item 2, it will also show siblings of Item 2 (Item 1 and Item 3). If you start your menu from Item 2, it will only show children of Item 2, and not Item 2 itself.
The closest you can get is to show the title and make it a link, then use CSS to make it look like a menu item and to alter the other menu items to look like they are children of the title.
Comment #3
rikki_iki CreditAttribution: rikki_iki commentedThe attached patch will give you an option to hide the siblings of all menu items in the active trail.
Example, if the active item is 1.1.2, the menu will show:
Where Item 1.1.1, Item 1.2 and Item 2 exist but are not rendered .
Comment #4
rikki_iki CreditAttribution: rikki_iki commented#3 had a line missing sorry, this one works better.
Comment #5
rikki_iki CreditAttribution: rikki_iki commentedThe last patch still wasn't working properly. The attached is better.
Comment #6
timdavison CreditAttribution: timdavison commentedI had trouble applying the patch, I got the following error: patch: **** malformed patch at line 98: + if ($config['hide_siblings']) {
However I applied the patch manually and it worked fine for me.
Comment #7
saitanay CreditAttribution: saitanay as a volunteer and at Acquia commentedLooks like this module has changed a lot since the earlier patch was created. Hence the patch would no more apply.
Recreated the patch based on the latest module. The functionality from the attached patch works as expected.
Every block now comes with a "Hide Siblings" option and when selected the siblings are hidden.
Comment #8
rv0 CreditAttribution: rv0 commentedPatch works fine, could use some work though:
- whitespace issues:
hide_siblings-1390526-7.patch:53: trailing whitespace.
hide_siblings-1390526-7.patch:67: trailing whitespace.
hide_siblings-1390526-7.patch:91: trailing whitespace.
warning: 3 lines add whitespace errors.
- code style:
looking at the patch, the code of the last code block in submit function could use some re-alignment.
- user interface:
the siblings option appears in "basic options", should be only shown in "advanced options"
Comment #9
saitanay CreditAttribution: saitanay as a volunteer and at Acquia commentedCleaner one.
Changes:
Whitespace issues, Moved the config to Advanced Section from Basic.
Comment #10
rv0 CreditAttribution: rv0 commentedComment #12
codevoice CreditAttribution: codevoice commentedConfirming that patch in #7 works as expected, thanks!
Comment #13
focal55 CreditAttribution: focal55 commentedI love what was done in this patch. I have the need to control the depth at which the sibling are allowed to show. I will supply a patch shortly.
Comment #14
focal55 CreditAttribution: focal55 commentedPatch to add an additional field to set a depth at which to stop hiding siblings.
Comment #15
focal55 CreditAttribution: focal55 commentedComment #19
heshanlkComment #21
heshanlk