Ok, I must be missing something obvious, but I'm having trouble adding a link to user/%/edit
to the main menu. In the Menu UI, I clicked "add link," set the title to "Account settings," and then was at a loss about what to put for the path. I know how to generate a link to the account edit page using views, which is what I've always done before, but this time I actually need to add the link to the "Main Menu."
4 Answers
In Drupal 8,9,10 etc. you can do this by providing a custom route to point to /user/edit
for example and have this route call a controller to perform a simple redirect. You can then simply link to /user/edit
from anywhere you want and the redirect will bring the user to their correct /user/%/edit
form.
The User Current Paths module does exactly that. Use this module or have a look a their approach, which can be extended easily to provide more complex dynamic redirects as well.
- The routing entry: user_current_paths.routing.yml
- The callback: src/Controller/UserCurrentPathsController.php
Try this module menu_token , it allows to use tokens in menu
Menu Token module provides tokens, that could be used in title or in path of menu items (links). For example, if you create a menu item with path: "user/[current-user:uid]", the url will be changed "on fly" to: "user/1" (assuming you are user 1).
You can't use % as a wildcard when adding a menu item like that.
The me aliases module can help you do it.
You install that module and then you can add a menu item to user/me/edit and it will go to the currently logged in user's edit page.
-
-
The 'me' aliases module changed all of my user admin links so I can't edit user tabs anymore so I won't recommend it. Jun 11, 2013 at 13:12
-
It's a valid solution that works for me. I don't see why it is worth a down vote as it is not a wrong answer. But whatever.– roobyJun 12, 2013 at 7:24
Create a node with input format filter set as PHP code and copy/paste the following code:
<?php
drupal_goto('user/'.$GLOBALS['user']->uid.'/edit');
?>
Under menu settings, create a menu link and add it to a menu.
-
1