Closed (fixed)
Project:
Menu Block
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Oct 2016 at 20:02 UTC
Updated:
14 May 2019 at 11:10 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
matsbla commentedComment #3
matsbla commentedUpdating issue to describe the problem better.
Comment #4
matsbla commentedComment #5
mogtofu33 commentedHere is a patch for this functionality.
Add 2 options for "Fix parent":
Please review and test.
Regards.
Comment #6
matsbla commentedThat patch came fast!
Works perfect :)
Thanks a lot!!
Comment #7
johnwebdev commented#5 works as expected. We had an additional use case where we needed the active trail parent, but not necessarily the first one. How about adding an additional option to the "Active trail parent" which allows you to select parent depth.
Comment #8
kevinquillen commentedNot sure this is working exactly as it should.
When I have 'Active Trail Parent' set, it does not make the menu block 'stick' for the children links. No menu shows at all for a third level item, but does show for a second level item.
I want the second level of the menu tree to always show if I am on a third level item. Not just the parent. "Active Trail" should be what I want (I think), but the menu just goes away.
When I am on the
parent1node, I should see the entire tree below it, same for if I click on child 1.1, I want to stick at that level. Child X, same, show that first level tree.Comment #9
kevinquillen commentedComment #10
kevinquillen commentedJust poking around a little:
This will always select the previous link. If I edit that and make it uses the first link, I get the desired result. How can we implement an option to tell it which level to force the trail to begin from?
Comment #11
matsbla commentedYou are right, seem like this is not entirely working with several menu levels!
To me it also seems like it counts "Initial menu level" from current active node, and not the menu tree itself, so the menu is displayed at some levels, and others not.
Maybe it would make more sense to only fix specific menus inside "Fixed parent item" and then have a check-box under to filter menu options on that fixed parent item to active trail / active parent trail?
Comment #12
kevinquillen commentedI think you need to allow fixed parent level, to 'pin' the menu tree at a given spot for anything under it.
I was able to do it by adapting it to:
I don't pop the array because at the first level, it removes the parent, which doesn't generate a tree. Now, when I visit anything at that level, the entire tree under it shows for that section just the way I want it to. No matter where I am now after the first level, I see the menu tree in my left sidebar. The depth is still capped at 3 (for me) and this appears to work though is by no means a true solution.
I think we need a new option to enable this and update the code to reflect this. Some people might like the menu constantly drilling into the tree with parent depth -1, but I just want to pin an entire section of the tree no matter where I am.
Comment #13
kevinquillen commentedHere are some changes incorporating the original patch.
I did not have a lot of time to dig into it, but I added an option "Fix to parent level" for the active trail parent option. When enabled, it should use the 'initial menu level' as the root level to set for menu block.
I tried a few different kinds of logic to get the menu link ID. While each one was correct, the tree below is never built. Hopefully someone can view and expand on this.
Comment #14
sutharsan commentedIf I compare the Drupal 8 module behavior to the Drupal 7 module behavior, I consider the Drupal 8 behavior as a bug. I have made a menu structure and configured two blocks. One to show the top level, one to show the levels below the top.
"Below top" configuration:
Drupal 7 result:

Drupal 8 result:

Comment #15
sutharsan commentedInspired by the Drupal 7
menu_tree_prune_*functions, I've created a manipulator (like \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators) that prunes the menu tree and saves the active tree.Note: Not providing an interdiff as the patch takes a different approach.
Comment #16
vlad.dancerI agree with you. Let's imagine that tree on attached screenshot has the whole items expanded ))
I've fixed this using a bit easier approach, patch will come later:
Comment #17
vlad.dancerAlso I think we have two different feature requests and one bug. I assume that this issue should be splitted into separate ones.
Comment #18
vlad.dancerHere is an alternative patch. It will add a new option in the block configuration "Expand only active tree", when you select "Expand all menu links" option.
Comment #19
johnwebdev commented#12 gave me an working solution for all of our use cases.
Comment #20
matsbla commentedBoth #15 and #18 are working. However there is a small difference about which menu items that are displayed at the inital menu level; In 18 you only see the active trail (no other options at initial menu level) whereas in #15 you will also see other menu items at initial menu level with same parents as the active trail (like displayed at screenshot in issue). I guess both results can be desirable in different scenarios and maybe it should be configurable, however to me #15 seem most intuitive (however maybe it should be a default instead of a config option?)
Patch in #13 & #5 are not working, and I do not think we should solve this issue by adding any dynamic options under "Fixed parent item".
Comment #21
nelslynn commented#18 works great for me! I might add, it also works with this patch. The patch combination makes the module just like the Drupal 7 version. It would be nice if both patches were committed :)
Thanks!
Comment #22
aaronbaumanThis duplicates pending core patch: #2631468: Menu subtrees in menu blocks show all subitems regardless of the active menu item
Comment #23
aaronbaumanComment #24
rutiolma#13: the patch you posted seems to work although it doesn't seem related with this issue but with this one https://www.drupal.org/node/2756675
It would be nice to publish the patch there.
Comment #25
Gertjan.k commentedI didn't get the expected results with all the patches. I've rerolled #2631468-95: Menu subtrees in menu blocks show all subitems regardless of the active menu item to fix this when using MenuBlock.
Comment #26
Syndz commentedReopened the issue as the menu block currently complete overwrites the SystemMenuBlock::build method and therefore does not profit from the core patch.
MenuBlock::build should probably extend SystemMenuBlock::build rather than overwrite it in the future.
The patch in #25 breaks the "Fixed parent item" functionality.
Here's a new patch that should solve that problem.
Comment #27
kevinquillen commentedI am running into an issue which may or may not be related to the changes made in this thread:
#2859703: Incorrect parent tree shows when the same URL is used in menu links many times
I cannot figure out how to get menu block to behave correctly when multiple links to the same content are present in the same menu.
Comment #28
petergus commentedI wanted to show the root level item but I could not so I had to resort to this patch to show the highest parent in title.
Suggesting a way to also show the highest parent. i.e. see parent 1 and everything below when on parent 1 or anything below.
Parent 1
- Child 1.1
-- Grandchild 1.1.1
-- Grandchild 1.1.2
- Child 1.2
-- Grandchild 1.2.1
-- Grandchild 1.2.2
Parent 2
- Child 2.2
-- Grandchild 2.2.1
-- Grandchild 2.2.2
Comment #29
yannickooThe patch from #26 works nice, thank you Syndz :)
I have renamed the variable
$fixedParentMenuLinkIdto$fixed_parent_menu_link_idand moved the max depth into a variable.Comment #30
RumyanaRuseva commentedPatch #29 works perfectly, the code also seems correct.
Thank you yannickoo, Syndz and everyone.
Comment #31
johnwebdev commentedWhy do we test it for being a string as well?
Comment #32
Syndz commentedThat's a good question johndevman, but that part of the code isn't a part of this patch, perhaps a new issue should be created for that question?
Comment #33
johnwebdev commentedI only raised the concern as the patch does implicitly assume it's an int. PHP magically casts it to an int in any case but I would say it's better practise to make sure it is actually is an int by explicitly casting it.
Comment #34
matsbla commented#26 works for me.
+1 for fixing this bug soon!
Comment #35
gsquirrelI have also tried #29 patch and it does seem to work, restricting the 2nd level links to those under current menu trail/parent..
Comment #36
Miri Meltzer commentedpatch #29 worked fine.
@Syndz & @yannickoo, Thanks.
Comment #37
joelstein commented#29 works great for me, thank you!
Comment #38
rferguson commentedCan #29 get rolled into the stable release? Just tried, and it works.
Comment #39
tinarey commented#29 works for me too, thank you!
Comment #40
nickvanboven commented#29 works for me, thank you!
Comment #41
devil2005 commentedIs it possible to publish a dev version with all patches ?
Thanks
Comment #42
caiobianchi commented+1 for a patched dev version.
Comment #43
jimkeller commentedSee my comment here for a patch that includes three of the major outstanding issues, including this one: https://www.drupal.org/node/2757143#comment-12137846
Is there any update on when these patches can get added to the release version?
Comment #44
adammalonePatch for the dev version attached.
Comment #45
woutervu commentedCombined #5 (mogtofu33) and #18 (vlad.dancer) and added functionality:
--
These were things that were missing for our use case.
Comment #46
devil2005 commentedI tested these 3 patches applied on stable version on the module but nothing happened
Comment #47
woutervu commentedMy patch combines #5 and #18. Do they work seperately?
Do you see nothing in the advanced settings of your menu block? If so, you may need to recreate the block and check again.
Comment #48
devil2005 commentedPatch apply require manual workflow, automatic is broken...
So i have applied #5 then #8 then #45... And now it seem to work... Don't know why.
Thanks for the patch :)
Comment #49
woutervu commented@devil2005: Hopefully it's useful! And thanks to mogtofu33 and vlad.dancer who laid the groundwork with the active trail/expanding of the active tree :)
Attached is a new patch. Removed unnecessary anonymous function. Functionality remains the same.
Comment #50
Johnny vd Laar commentedYour patch didn't apply anymore and didn't work on drupal 8.4.0-rc1. This patch does.
Comment #51
Johnny vd Laar commentedIgnore this one!
Comment #52
Johnny vd Laar commentedAnd this patch is for users of the 8.x-1.4 branch.
Comment #53
isaiah nixon commentedThe patch from #29 worked perfectly for the menu system I needed when combined with #32 from #2756675.
Comment #54
strykaizer#29 works for me, no need for any other patch.
PS: #52 introduces a lot of extra settings, which are confusing (if we need them, please document with examples) and did not fix the issue for me.
Comment #55
anybody@Maintainer: It would be great to have this issue fixed and committed.
In the meantime #29 seems to require a reroll against the latest dev?
Comment #56
mqannehRerolling #52 against the latest dev version since it failed to apply.
Comment #57
mqannehPatch.
Comment #58
mqannehRerolling #29 against the latest dev version since it failed to apply.
Comment #59
devil2005 commentedI tried all patchs, parameters combined... nothing works... on dev or stable version of the module and drupal 8.4.4
@mainteners : can you please upload a working version with all patches ? thanks a lot a lot a lot :)
Comment #60
joelstein commentedI had make one small tweak with the "Active trail custom depth" option when custom depth was 0, which I could resolve by consulting the "Initial visibility level". I also removed the unnecessary function setActiveTrailLevel() function.
Comment #61
Jorge Navarro commented@devil2005 #60 works to me, are you sure you are choosing "active trail" under Fixed parent item?
One think that I couldn't get working is the tree, should not show the active trail parent levels if "active trail parent"?
Additionally, we need to think if at the end of the active trail we should show the siblings as an option.
Thanks for all the work!
Comment #62
rutiolmaIf anyone gets as confused as I did, let me clarify this issue a bit (correct me if I'm wrong).
The only patch that really seems to address this issue is #29 (or #44), which was widely RTBC. Starting on patch #45, all the patches are fixing both this and #2756675. It's nice to have such patches, and thank you for all the work, but it got a bit confusing.
Can't we just merge both issues (closing the other one) and avoid duplicated code on both? It would be nice if a maintainer would have a look at this so we would join efforts to fix these issues.
With this said, I think #60 is a good one and it works for me although it would be nice to have some tests.
Comment #63
devil2005 commentedTested on Drupal 8.5 and i've got an error
[level=error], [msg=AH01071: Got error 'PHP message: PHP Fatal error: Call to a member function getActiveTrailIds() on null in /modules/menu_block/src/Plugin/Block/MenuBlock.php on line 200\n']with the patch
thanks
Comment #64
kevinquillen commentedThat has to do with this. #2951298: Update required for 8.4.x+, MenuActiveTrail service has been removed
Comment #65
devil2005 commented@kevinquillen : oh thanks a lot that all works ! :)
Comment #66
johnny5th commentedI may be doing something completely wrong, but I cannot for the life of me get a 3 menu depth starting from level 2. Turning "Expand all menu links" on shows *all* second level menu items, regardless of active trail. Turning "Expand only active tree" removes the depth of the menu if I'm on a second level page. When on a third level page, the 2nd level menu shows the 3rd level (not the desired 4th level too) under the active page that I'm on.
Regardless of the settings, should "Expand all menu links" with a level > 1 show items outside of the active trail?
I threw in some of the logic from https://www.drupal.org/project/drupal/issues/2631468#comment-12079948 and it fixed it right up.
Comment #67
dddbbb commentedThis issue is a total mess! Thanks for all the work though people.
This worked for me:
Drupal 8.5.0
menu_block dev-1.x#cc5fc51 (latest dev at time of writing)
Patch #60
UPDATE
Scratch that. It's almost working but the patch in #60 now means that my block is always rendered, even if it has no menu items to display. It also appears to be ignoring the "Initial visibility level" setting.
Comment #68
kferencz91 commentedCan confirm that I am running into the same issue as @danbohea. Block always seems to render, even if there is nothing to render.
Comment #69
joelpittetThis diverted lots, I'll look at committing #29 or a variant of that. The feature request should be in it's own issue to expand the active trail.
Comment #71
joelpittetI've committed #29 to the latest -dev release. Please create a follow-up feature request for the other patches.
Comment #72
rutiolmaNice to have this issue fixed and a new stable release!
All the work done after patch #45 (including the working patch #60) may be addressed on #2756675
I've created a patch similar to #60 that applies on menu block 1.5 here
Comment #74
devil2005 commentedIs it ok on the 1.5 stable version ?
I'm unable to make it works...
Thanks
Comment #75
saschahannes commentedYou could try the 8.x.1.x branch it seems to be working. @devil2005