Problem/Motivation
In the current version of the module, the user Navigation block situated at the bottom of the Navigation bar consists of a set of custom links defined in \Drupal\navigation\UserLazyBuilder::userOperationLinks. It is not using the "User account menu" or any other mechanism to allow a site admin to adjust the links presented within the block. @catch asked why we have this approach in the core MR (#3438895: Add the new Navigation to core as an Experimental module). Link to the specific, relevant comment:
https://git.drupalcode.org/project/drupal/-/merge_requests/7474#note_297387
It appears the current implementation has continued unchanged from early in the development lifecycle and the implementation hasn't been sufficiently scrutinized.
A couple of things would be different if we use the "User account menu". First, we would lose the "Edit profile" link. Second, the default label would be different. We currently have "View profile", core has "My account". Finally, the "User account menu" is often a user-facing menu whereas what navigation is trying to achieve would be different in many ways and may evolve differently from the "User account menu".
Proposed resolution
- Create a new "Navigation user links" menu when installing the module
- By default, use the same set of links in the new menu that are currently hardcoded
- Use the new menu for the User Navigation block (
\Drupal\navigation\Plugin\Block\NavigationUserBlock - Take care to mitigate any potential caching issues
- Consider a fallback for the "Navigation user links" menu missing
Remaining tasks
Needs a FunctionalJavascript test.
User interface changes
Nothing visible. Only the underlying data structure / sources are changing.
API changes
None.
Data model changes
New "Navigatoin user links" menu is introduced on navigation module installation.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | Screenshot 2025-02-04 at 11.42.59.png | 93.12 KB | gxleano |
| #47 | Screenshot 2025-02-04 at 11.40.42.png | 30.37 KB | gxleano |
| #45 | 3441576-nr-bot.txt | 90 bytes | needs-review-queue-bot |
| #34 | 3441576-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-3441576
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:
- 3441576-user-menu
changes, plain diff MR !9904
Comments
Comment #2
m4oliveiComment #3
m4oliveiComment #4
skaughtHow User menu is made: User menu is provided by a Menu Plugin (YAML FORMAT)
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/user/...
user login/logout item:
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/user/...
items itself dynamically changes title & path. cache content 'user.roles:authenticated'
src/Plugin/NavigationBlock/UserNavigationBlock.php
- We are providing our own placeable block but not placing it. which is why we see 2 user blocks 'Navigation blocks' admin (admin/config/user-interface/navigation-block)
- secondarily, we're using the same namespace 'user'. should be renamed to keep more separation for when a site may want to place the traditional list of 'Account Items'
Realization:
user.module itself provides the account links for toolbar (toolbar is not using User Menu links)
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/user/...
- in contrib: Gin Toolbar also provides for it's own user links.
- Navigation should have a listed dependency on User module. Catch is point to this loosely as we are using user routes.
Comment #5
catchIf this needs to be different to the user account menu that would normally be in the front end theme (brought up by @ckrina on the MR), then it might also be possible to define an additional menu like 'Navigation user links' so that they're separate - but that would still allow people to add an extra link or remove something if they want to.
Comment #6
ckrinaAgreed. I missed the part about customizing the links. Tagging this as Stable Blocker.
Comment #7
ckrinaComment #8
aaronmchaleHaving the "User account menu" and the user account links that appear in the toolbar being different does feel like a weird quirk, from a UX perspective I think using the "User account menu" and "modernizing" it makes a lot of sense. As noted, it also allows the user menu links in the toolbar to be customized, which is a win in my opinion. I think it would be weird if every other menu in the Navigation could be customized apart from the user links.
Comment #9
catchThere are sites that customize the user account menu links with links that they might not want in the navigation toolbar, however, if it's just a menu block in the layout, those sites could swap it out with a different menu block easily enough. So using the same block by default might be plenty?
Comment #10
aaronmchaleAgreed. We should think in terms of what's the most sensible default for the 80% use-case. As you say, they can always use a different menu on the front-end, or swap this one out for a different one in the navigation.
Comment #11
ckrinaComment #12
plopescComment #13
plopescAdding #3443452: [PP-1] User menu block render array is cached per user as reference to deal with caching at user level issues.
My concern or question about how to integrate a menu here is because most of the links I think that could be added to this menu are user specific, like
/user/XX/fooand I am not sure how we could handle routes like that from a menu.Mostly thinking about menu links created from the UI by site admins, where it is not possible to indicate URL parameters.
Core's user routes provides shortcuts like /user or /user/edit that redirects to the user specific page, but that's something not all the contrib modules that provide user specific routes or views that use the user ID as parameter would support.
We could encourage the usage of modules like https://www.drupal.org/project/user_current_paths or https://www.drupal.org/project/me_redirect for this menu, though.
Comment #14
plopescNow that #3445993: Provide a NavigationLinkBlock Plugin and use Help as an usage example is closer and we are pushing again towards Navigation stability, I would like to make a proposal for this one:
Navigation User Links, or a better name to be proposedNavigationUserBlockclass will give the ability to choose a menu to render as user links. By default we would use the Menu provided aboveNavigationUserBlockwould render by default the links from the menu stored in config. If empty, or the Menu does not exists, it would fallback to the hardcoded links we have now. In this way we will ensure that removing the menu will not lead to unexpected behaviorsWould this proposal cover all the previously mentioned needs?
Comment #15
catch#14 looks good, with the slight caveat that I'm not sure about the fallback - could that be handled with validation maybe?
Comment #16
plopescValidation could be a good approach, and necessary.
My concern about validation-only approach is that selected menu could be removed from the system by accident, or deliberately, breaking the navigation. In that case, we might need to provide something.
If the concern is about cache, we could make it in a way where the block would not need to be cached per user, given that links in the fallback would be
/user,/user/edit&/user/logout, which are not user-specific.Comment #18
plopescOnce #3445993: Provide a NavigationLinkBlock Plugin and use Help as an usage example has been merged, started to work on this one.
Here is a brief summary of the approach taken to be validated.
navigation-user-linksPlease take a look and validate the approach before continue polishing and updating tests.
Comment #19
catchCouple of small comments on the MR. More general thoughts here:
- I think an extra menu is a good idea, allows it to be customized separately from any visitor-facing user menu.
- the js looks fine to me (which doesn't mean much because I am bad at js), although I wonder if there's a way to do it using core's existing lazy builder/big pipe workflow without additional js, but... I've never tried to do that with a menu link. And also we could look at that in a follow-up since it wouldn't be a data model or API change at all, whereas the new menu itself feels very stable blocking.
The very minimal fallback added here seems fine.
Comment #20
plopescTests are now green. We might need an extra FunctionalJavascript or Nightwatch test to validate the user name is replaced by JS successfully, but I would prefer to have the approval of the JS approach first.
Comment #22
catchOne thing to check here - does the current implementation result in the render cache for this block caching per-route. If so, it would be good if we're able to avoid that. The main reasons for per-route caching are the active trail for expanded menu links and maybe the 'active' class.
Comment #23
finnsky commentedjs not works
https://gyazo.com/f93eb21f5e7ddba4797e2cc9292d056f
Comment #24
finnsky commentedi fixed js but seems we need to care about reload again
https://gyazo.com/e1a88c9d32cbd215f97a11b6198d92b6
also keyboard search broken because button still has data-index-text="u". not sure it is critical. maybe we also need to move that functional out of twig to js
Comment #25
plopescThank you for your review @catch.
Made a couple of small changes from your comments and answered to one of you MR questions.
Checked at DB level and we are not introducing new items in the cache_render table related to this block.
Comment #26
m4oliveiThis is looking great. Just noticed two really tiny things in the menu wording. I don't see any other issues left to deal with.
The JS looks OK to me.
Noticing that we're still set to Needs work here. Is there anything else left to do here @plopsec that I'm not seeing?
Comment #27
plopescThank you for your review @m4olivei
It was still in NW because @finnsky noticed some possible issues with the markup and JS. Also, when the navigation is expanded a small glitch is perceived when the username replaces the "admin" label. I would like to know if there is any possibility to improve that behavior.
Comment #28
ckrinaAdding the "Drupal CMS release target" to see if we could hopefully get to it.
Comment #29
m4oliveiThis is ready for a re-revew. Summary of changes:
data-index-textto match the dynamic usename\Drupal\Tests\navigation\FunctionalJavascript\PerformanceTest. We're doing less isValid checks? I think this is a good thing.I also considered @catch's comment from earlier. For the reasons he mentions, but also as a way to address the small flicker @plopesc noted.
The trouble is that, as far as I can tell, the title of a menu link needs to be a plain string. I tried to create a new Menu plugin (
\Drupal\navigation\Plugin\Menu\MyAccountMenuLink) for use as the top level default menu link. My idea was to override\Drupal\Core\Menu\MenuLinkInterface::getTitleand return a render array like:This borrows from this approach in user module. The nice thing about this if it worked, would be that BigPipe would take care of intelligently replacing the username without our own custom Javascript, and handling the no JS case well too.
However, it white screens the site. Per the docs on the interface, that method should return a string.
Ultimately I don' t think the flicker is that bad, so at the most, I'd suggest we handle that in a follow up.
Comment #30
m4oliveiAlso, I realize the issue description doesn't accurately describe the latest developments on this issue. Here is a crack at revising it.
Comment #31
m4oliveiAdded a functional javascript test.
Comment #32
catch@m4olivei yeah menu link placeholder is tricky. I opened #3498922: Use a placeholder for the navigation user block to track the possibility, definitely shouldn't try to tackle it here (although thanks for trying, but I think that's enough to demonstrate that it's hard).
Comment #33
plopescI think we're in a good position to mark it as RTBC.
Comment #34
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #35
plopescBack to RTBC once conflicts have been solved.
Comment #36
catchMerge conflicts on the MR unfortunately.
Comment #37
plopescIt's green again once conflicts have been solved :)
Comment #38
catchSorry it took me this long to realise this - because navigation is beta stability, we need a post update that creates the
system.menu.navigation-user-linksmenu. Because it's beta, this doesn't need any test coverage, just the upgrade path and probably some manual testing would be good.I was just thinking about how great it was that the MR doesn't need an upgrade path, then it hit me that it does :/
Comment #39
plopescUpgrade path added and moved back to RTBC.
Comment #40
catchPretty sure the update should be a post update, not a hook_update_N(), because it relies on the entity API. Also was it manually tested?
Comment #41
plopescUpgrade path is now a post_update hook. Marking as Needs Review to get a valid manual review from the community.
Comment #43
ironnuts commentedComment #44
ironnuts commentedComment #45
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #46
plopescMR updated. Back to Needs Review.
Comment #47
gxleano commentedReview steps
Drupal 11.xdrush updbSee evidences:
Update database

New user navigation link

Everything works as expected ✅
Moving to RTBC.
Comment #48
catchUpdating issue credit, unfortunately this needs another rebase.
Comment #50
catchCommitted/pushed to 11.x, thanks!