Hi, does anyone know how to do this?
On a site where it's important that members work on their user profile, you don't want the edit tab to be the only pointer to where a user can fill in their profile.

The url of the profile edit page is user/uid/edit, uid being the unique user id, so you can't just put a static url in your menu to the profile edit page.
Is there a way to link directly to the edit page in page.tpl.php or in the menu module?

Thanks in advance,
JR

Comments

anantagati’s picture

If you want to put fixed link in page.tpl.php you can use this syntax:

<?php
print l(t('edit profile'), "user/{$GLOBALS['user']->uid}/edit");
?>

If you will use Drupal menu system you can create node (page, story) with input format PHP and to body write this:

<?php
drupal_goto('user/'.$GLOBALS['user']->uid.'/edit');
?>

After you will create menu item with url of the created node. When somebody will click on the link he will be redirected to edit his profile.

JurriaanRoelofs’s picture

thats awesome thanks.

-------------------------------
http://www.sooperthemes.com/#-Drupal-Themes

ikiam’s picture

The Code is Perfect BUT now in Drupal 7, the only problem is when the cron is executed for some reason this is redirected to http://example.com/user/0/edit and then I get the error message "access denied" and no cron is executed while the page created with this code exists,
:S

Some solution?

Thanks

bfbryan’s picture

an image instead of the "edit user" text?

MarcoR’s picture

Look for the link command of drupal. http://api.drupal.org/api/5/function/l
This is how l() is defined:

l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE)

You see l() has more arguments than just 2. Last argument has to be TRUE. Then the text is interpreted as HTML and you can put an img-tag into instead of the text.

;)

bfbryan’s picture

My only remaining issue is creating hover text for the image. Here is my code. Can you advise?

print l('<IMG src=" /irp/themes/mydrupal/mydrupal1/icons/tag_blue_edit.png" align=right>', 
"user/{$GLOBALS['user']->uid}/edit", array('title' => 'edit user'), NULL, NULL, FALSE, TRUE);
MarcoR’s picture

<?php
print l('<IMG name=mypic id=mypic src="/irp/themes/mydrupal/mydrupal1/icons/tag_blue_edit.png" align=right
onMouseOver="this.src=otherpic.png" onMouseOut="this.src=tag_blue_edit.png">',
"user/{$GLOBALS['user']->uid}/edit", array('title' => 'edit user'), NULL, NULL, FALSE, TRUE);
?>

Substitute paths.
Look for onMouseOver and onMouseOut in HTML/Javascript documentation, if theres something wrong.

;)

entendu’s picture

This page is a little out of date -- if you're using D6

In template.php:

function mytheme_preprocess_page(&$vars) { //See http://api.drupal.org/api/function/template_preprocess_page/6
  global $user;
  //other stuff...
  $vars['edit_profile_link'] = $user->uid ? l(t("Edit my profile"), "user/" . $user->uid . "/edit") : NULL;
}

In page.tpl.php:

if($edit_profile_link) {
  print $edit_profile_link;
}
schvili’s picture

Thank you for your update for D6. Is there a way to link to the page in the menu system.

Babalu’s picture

i would like to have this to. a menupoint to the profile edit form
how i can do that ?

chazz’s picture

drupal_goto('user/'.$GLOBALS['user']->uid.'/edit');

this code doesn't work...

whan’s picture

Create a node (page/story) with Input format filter set as PHP code and copy the following code.

<?php
drupal_goto('user/'.$GLOBALS['user']->uid.'/edit');
?>

The menu link to latter created node should redirect to the user edit page.:):)

froboy’s picture

Thanks!

vthirteen’s picture

@entendu http://drupal.org/comment/reply/102162/2431068#comment-2431068
if you add a preprocess_page function then edit_profile_link will work in the page.
i tentatively changed function MYTHEME_template_preprocess_block(&$variables) to make the variable available in a block but it doesn't print anything...

andrew.lansdowne’s picture

This can be done via code in a custom module e.g.: (search for module creation guide for how to set up a module and then put this in the .module file)

function MODULENAMEHERE_menu() {
  $items = array();
  $items['user/edit-my-profile'] = array(
    'title'            => 'Edit Profile',
    'description'      => '',
    'page callback'    => 'MODULENAMEHERE_edit_my_profile',
    'access arguments' => array('access content'),
    'type'             => MENU_NORMAL_ITEM,
    );

  return $items;
}

function MODULENAMEHERE_edit_my_profile() {
  global $user;
  drupal_goto('user/'.$user->uid.'/edit');
}

Then when you enable the module the link will show up in the Navigation menu for you to with as you please.

stevenx’s picture

Thanks it works.

grimal’s picture

You can do that without redirect, using the same core user module menu options and functions:

function MYMODULE_menu() {
  $items = array();
  $items['user/edit'] = array(
    'title'            => 'Edit Profile',
    'description'      => 'Edit own profile',
    'page callback'    => 'MYMODULE_user_edit',
    'access callback'  => 'MYMODULE_user_edit_access',
    'type'             => MENU_LOCAL_TASK,
    'file'             => 'user.pages.inc',
    'file path'        => 'modules/user'
  );
  return $items;
}

function MYMODULE_user_edit() {
  global $user;
  $account = user_load($user->uid);
  return drupal_get_form('user_profile_form', $account);
}

function MYMODULE_user_edit_access(){
  global $user;
  return user_edit_access($user);
}
Andre-B’s picture

short information: this has to be a module, can't go in a theme (template.php)

follow me on Twitter: https://twitter.com/ABaumeier

jelo’s picture

Does this work with D7 or do I need to make changes to this module to work in D7?

deanflory’s picture

The me module creates a way to do this easy. I haven't done full testing to see if it was the culprit, but I was having some issues with my content profile bouncing back and forth between two redirects and I'm thinking it was the me module, but again not sure. But it does provide an easy solution to this issue.

http://drupal.org/project/me

JohnnyW’s picture

I just looked at views and see where the url is linked.

Then make a link in menu.

For example, I wanted edit tab say Edit Profile Info...
I tried using user/[user-id]/edit, user/%uid/edit....etc.

Finally, for this particular function on tab, it was user/%/edit...

So I made a menu item and linked it to user/%/edit... now they go directly to their Account Info and all Profile info they need to edit ;)

ahillio’s picture

I'm getting this error message when I try to give a menu link that path:

The path 'user/%/edit' is either invalid or you do not have access to it.

Huh?

leex’s picture

I think it worked for Nonnie because they had made a custom page at user/%/edit

GiorgosK’s picture

can also try http://drupal.org/project/menu_token module
should also do what you are looking for

------
GiorgosK
Web Development

nbouhid’s picture

Thanks ! it worked for me.

Just enable the module and check the token option, select the user from context and set the url to: user/[current-user:uid]/edit

simnav’s picture

I have installed the menu token module but there is no documentation. Please give me the steps how can i add the edit link on my custom page using this module.

frederico’s picture

Hello simnav, I found a patch that creates a readme.md file.  You can find documentation there at https://www.drupal.org/project/menu_token/issues/2878725.

Anybody’s picture

For Drupal 8 you may want to try: https://www.drupal.org/project/user_current_paths

http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes

Cangurin limpiezas’s picture

For Drupal 9 i use a simple custom module for create a link in "main navigation" menu to "user/{user id}/edit"

source in gitlab is here or if you prefer the source in github.

if you like that the link in menu main  go to profile edit page user (module profile), i make othe similar module, that create link to route "user/{user id}/main" the source in gitlab is here or if you prefer the source in github.

I tested the code in this site without problem, i hope this help.