Hello Team,
I am facing an issue when using [current-user:uid] token in the menu for the authenticated user. I have created a menu "My Dashboard" with URL /user/[current-user:uid]/dashboard. The token is getting replaced with the currently authenticated user until at very same time some other authenticated user access pages. Request finishing in last have a wrong replacement for [current-user:uid]
Example:
User 1 : John Smith (UID - 1090)
User 2 : Mark Web (UID - 1406)
I am testing it on the same computer with the different browsers. User 1 login in a browser on a machine. User 2 login on a different browser on the same machine. They both see the same menu in the top (Menu render from the block in navigation region). Now if I refresh both browsers at the same time (before request completes on the first browser), the link is not correct for request finishing later.
Can this be resolved from some settings in menu or configurations?
Comments
Comment #2
ariane commentedI have exactly the same error.
In my case I made a custom link with the path /user/[current-user:uid]/edit in a new block menu.
Sometimes the token replacement changes to user/not-assigned-yet/edit even when the user is logged in.
Comment #3
aperedos commented+1
Comment #4
godotislateWe ran into the same issue, and the issue is this:
Our less than desirable workaround was to add some code to re-replace the the token data in the links in the menu block render arrays after they have been built.
I think a better solution for the module would be to eschew updating the menu_tree table with replaced token values, and instead replace the tokens after menu tree data is loaded before menu is rendered.
Comment #5
eahonet commented@godotislate can you elaborate on your solution? I'm running into some issues using menu_token. Sometimes it won't output a current-user value after a clear cache. Your comments have me worried once I start having multiple users testing the site.
thank you.
Comment #6
godotislate@eahonet, it's been a year or since I worked on the project using
menu_token, so my memory is a little vague on how it works. There's probably a better workaround, but basically, I created ayour_module.menu_builderservice that looks like this:The service class implements an interface:
And the service class:
Then, when assembling/altering the render array for the page/block/element/what have you, call the service's
buildMenu()method and use the returned render array as needed.Comment #7
vuilUpdate the issue to be "Feature request" because it is.
Comment #8
stijndmd commentedI don't see why this would be a feature request, to be fair. The token replacement for [current-user:uid] does not work.
It either straight up doesn't replace the "[current-user:uid]" string to the user id, or it changes the token replacement to "not-assigned-yet".
What was posted is a workaround to achieve the same goal.
Comment #9
lamp5Comment #10
develcuy commentedStill awaiting for a patch guys
Comment #11
vuilI added my employer only.
Comment #12
kenton.r commentedThis is because Views converts the link to a route and the when context looks to rebuild the link it is only looking for a url path. The patch #27 in menu_token/issues/2921178 looks for routes and promotes URL to matching routes to maintain route permissions.
Comment #13
develcuy commentedSee: #2921178: Unable to get [current-user:uid] when a link resolves to a route
Comment #14
develcuy commented