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.
Per #2757143: [Meta] Add missing features to Drupal 8 menu_block this feature hasn't been implemented yet.
Comment | File | Size | Author |
---|---|---|---|
#55 | menu_block-follow-2756675-55.patch | 8.09 KB | drclaw |
#55 | interdiff.txt | 8.63 KB | drclaw |
Comments
Comment #2
JohnAlbinComment #3
JohnAlbinComment #4
nod_Seems like this is working.
Comment #5
nod_extra space
Comment #6
manuel.adanI got an empty menu. Tracing it, I found that root menu item id in
parameters->activeTrail
was empty string, probably as menu itself. The new patch also doesn't alter the activeTrail array.Comment #7
matsbla CreditAttribution: matsbla commentedI think the patch that came in this issue includes this:
https://www.drupal.org/node/2811337
Comment #8
matsbla CreditAttribution: matsbla commentedComment #9
Tom.Camp CreditAttribution: Tom.Camp at CivicActions commentedThe patch from #6 was throwing an Undefined index error for existing blocks. I added 'follow' to the defaultConfiguration array and that fixed the issue.
Comment #10
AaronBaumanStill not quite there.
Given the following menu structure:
A
- B
-- C
--- D
and given placing a menu block with level = 1, depth = 2
Then when I navigate to node A
Expected behavior:
Menu block shows items A and B
Observed behavior:
Menu block shows only item B
Then when I navigate to node C
Expected behavior:
Menu block shows items C and D
Observed behavior:
Menu block shows items B and C
Comment #11
AaronBaumanThe more closely I'm looking at this, the more I think it's superseded by #2631468: Menu subtrees in menu blocks show all subitems regardless of the active menu item
If I'm mis-interpreting the intent of the "follow" option, then can someone please spell it out more clearly?
Keep in mind that the core Menu Block works differently than Drupal's old core menu blocks, so "make it work like in D7" is no longer sufficient.
Comment #12
Tom.Camp CreditAttribution: Tom.Camp at CivicActions commentedAaron, I've attached a patch that adds a checkbox for *Current page as top level*. If checked this will show the page that you are on as the top menu item. So in your example if you are on page C, it will show C and D. If you are on B, it will show B, C and D. If you only choose to show a depth of 2, it would show B and C and then wen you went to C, it would show C and D.
Comment #13
AaronBaumanThanks Tom, I think this clearly differentiates the "follow" and "current" behavior.
The "follow" behavior, best I can tell, is what's in #2631468
So, the ways forward are:
i'm not sure the best way to go -- I'll defer to maintainers there.
Patches thus far represent option number 1
Comment #14
lpeabody CreditAttribution: lpeabody commentedI've been testing this out, and I cannot get it to do what I expect this to do.
Given the following menu structure:
- Root
-- A
----1
------a
--------iv
--------vi
------b
----2
-- B
-- C
And the following selected:
Initial menu level is 1.
Maximum number of menu levels to display is 2.
Fixed parent item is Main navigation.
When I'm on menu item 1, I would expect to see the following menu block:
------a
--------iv
--------vi
------b
But I get:
----1
------a
--------iv
--------vi
------b
Which is counter intuitive to me. I already know I'm on the current page, why add the current page as the root in the block?
My expectation is that "Current page as top level" essentially overrides "Fixed parent item", but that doesn't appear to be the case.
Maybe there needs to be an option for setting starting depth? Or an option to hide the parent element?
Comment #15
cman9090 CreditAttribution: cman9090 commentedPatch #8 is good. However is it possible to make sure if you are on the last level and their no more children, to show that current level and its parent? For instance:
1
--2
---3
----4
----a
----b
if im on 4, it only shows 4 but I want it to show:
3
-4
-a
-b
Comment #16
cman9090 CreditAttribution: cman9090 commentedAlso for some reason the first item in a menu does not show as active trail if it is the page that is active, but any other menu item that is not the first will show as active if you click on it? edit. fixed this with the menu trail by paths module.
Comment #17
Gertjan.k CreditAttribution: Gertjan.k at Nedbase commentedI've extended patch #8 with the functionality described in #15. I've added a checkbox. When it's active and the current page doesn't have children then the root of the menublock is changed to the parent of the current page.
Comment #18
Gertjan.k CreditAttribution: Gertjan.k at Nedbase commentedI've rerolled #17 to work in combination with patch #11 of #2809699-12: Add configuration options for dynamic block titles
Comment #19
Gertjan.k CreditAttribution: Gertjan.k at Nedbase commentedPatches #17 and #18 don't work properly. I reverted back to #7 and used a difference approach to my usecase.
Comment #20
rutiolmaAdding the feature, like on D7, "Make the starting level follow the active menu item." seems to be fixed by comment #13 here
Comment #21
stefan.r CreditAttribution: stefan.r commentedcross posting that patch from #2811337-13: 2+ level menu block not limited to active parent
Comment #22
AaronBaumanstefan.r can you explain your intent in cross-posting the patch?
If you believe there is functionality from 2811337 which needs to be included into the current thread, you should explain the delta and provide a new merged patch.
Also:
I still think this entire thread will change drastically based on #2631468
Is it worth pursuing this patch before 2631468 lands?
Comment #23
smazI'm not having much luck with this patch either. Two issues:
1) If a menu item has no sub items, it displays all items from the current level rather than not displaying anything. I fixed this by removing the line:
This seemed to set it to an empty item, which would fully load the menu tree when it gets to:
2) If an node is not in the menu, it would display the top level menu items.
Again, I think this is because of the above snippet about loading the tree. After some brief testing, it appears that if a node is not in the menu the active trail will just contain a single, empty item. If it is in the menu, there will be two keys, with one of them containing content.
By adding the following, it will not continue if the active trail is empty:
I add this above the following line:
Comment #24
Gertjan.k CreditAttribution: Gertjan.k at Nedbase commentedI've rerolled #9 (The best working patch for me so far) to work in combination with #2811337-26: 2+ level menu block not limited to active parent. Setting a starting level also didn't work so I fixed that too.
Comment #25
rutiolma@aaronbauman the patch stefan.r cross posted at #21 solves the problem as described at this issue by adding an option to make the starting level follow the active menu item - check screenshot attached.
Menu Block D7 "follow active trail" is supposed to work in the same way as described at #14 and not as described at #10 or #15. Basically this option will allow to dynamically change the "parent" to the active page instead of keeping it fixed, making it possible to create a navigation with a breadcrumb (ancestors) and menu block (children).
Working example using the D7 version of this functionality: https://www.belgium.be/en/economy
Ancestors in the menu: Root > Economy
Current page: Business
Children menu trail items: Creation (plus a 2nd level), Regulated occupations (plus a 2nd level), Taxation and accounting (plus a 2nd level)
As far as I understand, this issue is not the same as #2631468 or #2811337.
None of the other patches posted in this issue queue worked for me to fix the described problem, only the one from comment #21 which should be considered.
Changing this to RTBC for patch at #21, but it's important to have more testers.
Comment #26
maseyuk CreditAttribution: maseyuk commentedEdit: sorry what I said wasn't valid and I cant delete my comment, this is causing the issue I was experiencing I think
https://www.drupal.org/node/2642816
Comment #27
polynya CreditAttribution: polynya at Edo commentedI have rerolled patch #24 to be compatible with patch #29 for #2811337: 2+ level menu block not limited to active parent. I have also changed variable $maxDepth to snake_case $max_depth for consistency.
Comment #28
devil2005 CreditAttribution: devil2005 commentedIs it possible to publish a dev version with all patches ?
Thanks
Comment #29
devil2005 CreditAttribution: devil2005 commentedIs it possible to publish a dev version with all patches ?
Thanks
Comment #30
caiobianchi CreditAttribution: caiobianchi commented+1 for a patched dev version.
Comment #31
adammaloneI might be wrong here but installing menu_block from scratch and applying the patch in the other thread, then the one in this thread didn't allow me to place blocks. My reroll is based on the work of #27.
Super basic patch here as I only added in the follow configuration to defaults. Should be an easy RTBC
Comment #32
sherakama CreditAttribution: sherakama commentedPatch in #31 did not apply to dev or latest stable (1.4) so I am re-rolling it here with a couple of updates.
The menu starting level and depth should still apply to the root item and should be set to 1 and 1 respectively if you want only the sibling items of the active path.
Comment #33
sam.spinoy@gmail.com CreditAttribution: sam.spinoy@gmail.com at Adapt commented#32 does not work for me. I have a menu like so:
- A
- - B
- - - C
Config is set to show only one level of depth and to follow the active trail, so I only want the direct children of the current page I am on. But no matter what page I am on, it always shows menu item B.
Comment #34
devil2005 CreditAttribution: devil2005 commentedsame for #32 broken...
any one know what's the right order to apply patches ? since stable or dev version ?
thanks a lot
Comment #35
adammaloneThe patch in #32 will apply in the following conditions:
Comment #36
devil2005 CreditAttribution: devil2005 commented@Typhonius : i applied patches as you explained but nothing happened, no now parameters in module or block...
Comment #37
wheretoplaygames CreditAttribution: wheretoplaygames commentedtyphonius: There is no patch on #30 on that page.
Anyonne have a comprehensive patch to apply to the latest dev or stable?
Comment #38
dieppon CreditAttribution: dieppon as a volunteer commented@wheretoplaygames what @typhonius means is #44 is the patch that ends with 30 on its name.
Comment #39
mithenks CreditAttribution: mithenks at bmeme commentedHello,
I've added an option to show the "direct parent" when following the active trail of a menu.
This can be useful because in this way the user can go backward.
The patch must be applied after the one for #2811337, as stated in #38.
Maybe this can be useful for everyone. If not, please ignore this version.
Regards,
Comment #40
Eyal ShalevThe patch in #39 conflicted with the patch for Menu parent as block title because they both edited the configuration form for the block.
This patch moves the positioning of the added lines to avoid conflict.
Comment #41
Eyal ShalevThis patch moves the positioning of the added lines to avoid conflict with Menu parent as block title (see #40), and adds the option to follow the parent all the way until the root of the menu (not including the root), and hide a menu if the current page does not appear in it.
Comment #42
dddbbb CreditAttribution: dddbbb as a volunteer commentedThe patch in #41 works for me with the exception that pages that should not render the menu block now render an empty menu block.
Comment #43
pookmish CreditAttribution: pookmish commentedJust re-rolling #41 since it was failing to patch due to recent changes on the main branch.
Comment #44
dddbbb CreditAttribution: dddbbb as a volunteer commentedJust tested the patch in #43 with the 8x-1.5 release and it applies cleanly and works as expected (thanks).
Concerns raised in #42 still apply though so leaving status set to "Needs work".
Comment #45
rutiolmaThis is another approach to fix this issue and was wrongly being developed on issue #2811337.
The UI of #43 is more user friendly and that may be the way to go, but I'm attaching a patch based on #2811337 - comment #60 which may be useful to someone, like me, that was using it and doesn't have the time to make a migration path to apply patch #43.
Comment #46
pookmish CreditAttribution: pookmish commentedThe attached patch takes #43 and uses the blockAccess() method to simply say the block is forbidden if there are no items. This prevents the block from rendering an empty block.
Comment #47
dddbbb CreditAttribution: dddbbb as a volunteer commentedThe patch in #46 almost works for me but seems to have a quirk...
If the block config contains a visibility rule (I tested "Hide for the listed pages" and added a single path) the menu block appears where I'd expect to:
- shows when there's menu items,
- hides when there's no menu items,
- respects the block visibility rule.
If I remove all visibility rules on the same block it will not render anywhere.
Comment #48
pookmish CreditAttribution: pookmish commentedHmm. @danbohea, I'm not able to reproduce that quirkiness. I repeated your steps and tried to add and remove various conditions like path, role, and content type. I experienced the correct desired outcome.
Scenario 1:
* added block with visibility to show only on path `/node/3` (child node)
- block only shows on /node/3
* removed visibility condition
- block shows on all pages with links.
Scenario 2:
* added block to all pages
- block is visible on pages with links.
* added condition to only show for anonymous roles
- block is visible when logged out
* removed condition
- block visible to all roles again on pages with links.
Comment #49
dddbbb CreditAttribution: dddbbb as a volunteer commentedPerhaps the issue I'm seeing relates to another part of the project I tested on.
¯\_(ツ)_/¯
Comment #50
johnny5th CreditAttribution: johnny5th at Encore Multimedia commentedGiven this structure:
-Root
--A
---a
----1
-----one
-----two
-----three
----2
----3
---b
---c
--B
--C
with initial visibility level: 2, number of levels to display: 2, Fixed parent on Main navigation, Follow active trail, following one parent.
When on page "a" the result I get is:
-1
-2
-3
when I expect
-a
--1
--2
--3
-b
-c
Yet, when I visit "1" the result I get is:
-1
--one
--two
--three
-2
-3
which is expected.
By tweaking the level calculation, it seems to make both scenarios work the same way.
Does that logic work?
Comment #51
byrond CreditAttribution: byrond at Palantir.net commentedWe were having the same issue as in #50, and the logic there works for us. There is also an issue when the level is > 1, and depth is set to unlimited (0). In that case, no children were being displayed, because the original depth wasn't being tested. This patch updates the line that tests for an unlimited depth.
Comment #52
KarlShea#51 worked for me.
Comment #53
2pha#51, why does it remove
$suggestion = $this->configuration['suggestion'];
?Should these new config items be added to the schema.yml ?
Comment #54
rmccreary CreditAttribution: rmccreary commentedSo for my needs i needed only the child items of the current page...
Given this structure:
-Root
--A
---a
----1
-----one
-----two
-----three
----2
----3
---b
---c
--B
--C
When on page "a" the result I want is:
-1
-2
-3
and, when I visit "1" the result I get is:
-one
-two
-three
Comment #55
drclaw CreditAttribution: drclaw at Fuse Interactive commentedHere's an updated patch with a few changes:
There's just one thing left I'm curious how to handle and that is what to do if you're following the active menu item, have the starting level set to 1, but you're on a page that's not in that menu. Currently we just fall back to the default functionality which is to "Use level 1 to always display this menu.", but I feel like if you're following the active menu item the menu should only show if the page you're on is part of that menu... Or maybe it could be an additional option?
Anyway, patch described above is attached with an interdiff.
Thanks!
Comment #56
johnny5th CreditAttribution: johnny5th at Encore Multimedia commentedI can confirm #55 works, and solved some issues with the prior patches. It also makes a heck of a lot more sense.
Comment #57
KarlSheaAlso confirming #55 works, and it does make way more sense.
Comment #58
dddbbb CreditAttribution: dddbbb as a volunteer commentedYep, liking #55 too. I had to tweak a couple things in config to get the same behaviour I had with a previous patch but it was possible, in fact the behaviour has improved and yes it makes much more sense reading back through the config now. Thanks @drclaw!
Comment #59
steveoriol#55 works for me too, thanks !
Comment #60
charly71 CreditAttribution: charly71 commentedThere is a plan to include patch #55 in next dev release?
Thanks
Comment #61
dddbbb CreditAttribution: dddbbb as a volunteer commentedComment #62
Kasey_MK CreditAttribution: Kasey_MK commented#55 is great, thanks!
I'd love to see some action on https://www.drupal.org/project/menu_block/issues/2756675 - sorting by the active item - presumably that could build upon this work.
Comment #64
joelpittetI've committed #55 to the -dev branch. Please try it out if you are after this feature.
Comment #66
idebr CreditAttribution: idebr at ezCompany commentedThis issue introduced new configuration options, but these options are not defined in menu_block.schema.yml. I have created #3022011: Implement config schema for block.settings.menu_block.*.{follow, follow_parent} to fix this.
Also created #3022012: Add automated tests to catch these issues when uploading patches in the issue queue.
Comment #67
Joshua_Lim CreditAttribution: Joshua_Lim commentedi cannot apply this patch??
it says
error: config/schema/menu_block.schema.yml: no such file or directory
why?? i put the patch file in the schema folder and also tried to put it in the menu_block folder and apply the patch. it will not work
sorry i'm a beginner
it also says if its in the directory outside
error: menu_block.install: no such file or directory
please help badly needed! i'm using drupal 8.6.4
Comment #68
alisonSorry for the difficulty, @Joshua_Lim, did you figure it out? Here's some documentation that might help:
https://www.drupal.org/patch/apply
(Are you using composer, or drush, or manually applying things, or?)
---------------------
Meanwhile, the patch from #55 works awesome for me, thank you!
Comment #69
natew CreditAttribution: natew as a volunteer commentedWe were using menu block 1.4.0 and an old patch (#32). I just updated to 1.6 and I don't think this patch is needed as most of the code appears to be there?