Problem/Motivation
Currently there is no way to set the block's title to the parent of the initial visibility level when this is set higher than level 2.
This is to me the expected behaviour when using "Active trail's root title", since the parent of the configured visibility level is the Active trail's effective root, however when is actually used is the 1st level item of the Active trail
Steps to reproduce
- Create a menu with the structure:
- Food
- Vegetables
- Grains
- Wheat
- Barley
- Drink
- Equipment
- Food
- Add a menu block that will appear on the Wheat and Barley pages with Initial visibility level configured as 3 and Use as title configured as "Active trail's root title"
- Navigate to the Wheat or Barley page
- Observe that the menu block contains Wheat and Barley, but that the title is Food rather than Grains
I don't imagine this is super useful to most people.
Proposed resolution
Update "Active trail's root title" to use the immediate parent of the visibility level rather than the 1st level item of the current trail. Have a patch ready for this.
An alternative approach would be to add a new option such as "Visible trail root" to avoid the situation where someone is intentionally using the current behaviour with a gap the trail (IMO this is unlikely, but people do their own thing).
Remaining tasks
Updated code has not yet been tested with "Make the initial visibility level follow the active menu item" option checked.
User interface changes
Menu Blocks with "Active trail's root title" set will display the parent of the visible portion of the active menu trail as the block title instead of the 1st level item in the trail as is used now.
API changes
None
Data model changes
In-memory only: Add a protected $menuRoot property to the Drupal\menu_block\Plugin\Block to propagate the $menu_root id from the build() method to the getActiveTrailRootTitle() method.
| Comment | File | Size | Author |
|---|
Issue fork menu_block-3321699
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 #3
agileware commentedComment #4
nikhil_110 commentedI implemented MR on my local machine using Menu Block Module V8.x-1.x-dev with Drupal 10.0.3. It is working properly..I have added the test steps and am attaching the screenshot for reference. Please review.
Comment #6
jwilson3RTBC++ I applied MR diff to version 1.10 and can confirm that this change does indeed fix the issue.
For purposes of calculating the Root title, the root should always be derived from the "initial visibility level" of the menu block, instead of using level 1, which may be too far up the tree to be practical.
The only thing I noticed is a minor grammar issue with the docblock in the MR, which I have updated but will leave as RTBC because it is a non-functional change.
Comment #7
joelpittetComment #8
zipymonkey commentedThe branch is out of date. I did a quick rebase locally and generated a patch (sorry for not updating the branch). I removed
$this->tree = $tree;since it did not appear to be used anywhere.Comment #9
zipymonkey commentedThis patch is working for me locally. Moving this back to Needs Review for others to review.
Comment #10
chroid commentedAssuming:
Home > Conditions & Treatments > Childhood Cancer Overview > Tests & Procedures To Diagnose Cancer > Blood Tests For Children & Young People With Cancer
Before patch:
After patch:
Menu block settings:
Initial visibility level:
3
Use as title:
Active trail's root title
So confirming here that this is exactly what we were after!
Thank you for the patch!
Comment #11
joelpittetWe gave this a try today, and it does indeed fix the issue. Since this was on my list to review for a while, I’m going to go ahead and commit it. Hopefully, there are no side effects.
Thanks, everyone, for your work on this and for your patience!
Comment #14
joelpittetActually, I’m sorry, but I’m going to revert this. It does what it says, but I’d rather not change it if someone already has it working. Also, the label “root” messes with my head a bit—it doesn’t clearly indicate that it moves around depending on Initial visibility level setting.
Comment #15
dhaval_panara commentedWe started facing issues from the day the PR was merged and patch is not getting applied to ^1.10. https://git.drupalcode.org/project/menu_block/-/merge_requests/13.diff.
I noticed a comment mentioning "changes reverted." Can you confirm if all changes from PR 13 have been reverted?
Comment #16
joelpittet@dhaval_panara As far as I know, this MR was reverted. It’s highly recommended not to use a GitLab MR URL as a patch because it can be changed at any time, breaking your build—or worse, allowing someone to inject malicious code. A safer approach is to download the diff and apply it as a local patch file.
Comment #17
joelpittetComment #20
joelpittetOk made a new branch with the new proposal in MR34, though needs a bit of testing, I like this because it won't change expected results from under people who consider root to be the top. Re-titling
Comment #21
joelpittetApologies for hijacking this! I hope the new feature/option is useful for everyone, and that I didn’t cause too much disruption along the way. 😃