I would like to create a menu link that takes the currently logged in user inside their own edit pages.

so the path would look like
user/{currentlyloggedinuser}/edit

What strategy could I use to accomplish this goal of linking a user inside their own edit page?

Comments

nevets’s picture

I am not clear on what you mean by "inside their own edit pages". If you have the tracker module enabled that places a tab under 'my account' that shows all the articles the person has posted or responded to. Or are you looking for something different?

dgeilhufe@yahoo.com’s picture

OK, I want to create a menu item.
The menu item has a path.

To go to user 1's edit screen, the path is user/1/edit

But I want the menu to be for the currently logged in user rather than hard-coded to a specific user.
user/{currentuser}/edit
If user 31 is logged in, the menu item would go to user/31/edit, for example.

David Geilhufe
Social Source Foundation
Try CiviCRM http://www.openngo.org/

nevets’s picture

The 'my account' menu entry takes you to user/{user_id} and the 'edit' tab takes you to user{user_id}/edit. Note that this page is for editing information about the user (not the posts they have made).

JohnG-1’s picture

is it possible to use a php $variable such as $uid or $user->uid in the path setting for a menu link from the navigation block?

a simple example would be a 'my posts' link
I have tried the paths:

tracker/$uid
tracker/$user->uid
tracker/{$uid} 
  (gives unicode: ".../tracker/%7B$uid%7D")
tracker/<?php print $uid ?>
  (gives unicode: ".../tracker/%3C?php%20print%20$uid%20?%3E")

and of course none of them link to .../tracker/1.

Does anyone know if it is possible and if so how?

Dublin Drupaller’s picture

Hi Geihufe..

I have done something similar before..not as a menu item, but in the profile pages themselves.

it's extremely useful if you want to point users to the specific profile editing page to change certain details.

For example, consider a user profile like this:

-----------------------------------------

Joe Drupaller (edit)
Drupal Guru

Drupal services inc. (Edit)
10101 Drupal street
Drupalville

Tel. 1010101010 (edit)
fax: 1010101011

My Drupal services:(edit)
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,

-------------------------------------------

So the edit links, that only appear if it's that user/admin, bring the user directly to the EDITING page they need to.

Is that what you want?

If it is, I recommend you check out the user profile page snippets, in particular the one that adds a "click here to add.." when fields are left empty.

hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

dgeilhufe@yahoo.com’s picture

Dublin Drupaller- very useful.

I'm actually doing this with CiviCRM profiles which basically replace the drupal profiles. The urls are formed: user/{userID}/edit/{profilename}

Based on the php snippets, I should be able to contruct a simple page that redirects the user to the edit page I want them to go to.

The strategy would be:
Use a menu entry to send the user to a page node with php that would redirect them to the page I want them to go to.

Menu item becomes: consutantregister
Create a page with a path alias consultantregister

!php noob alert!

PHP on the page:
1. Checks to see if they are logged in.
2. If yes, grab the userID
3. construct a URL in the format user/{userID}/edit/Consultant%Directory
4. redirect the user to that URL

<?php

//check to see if user is logged in
global $user;
if($user->uid)

// Construct the URL
$url= "user/$user/edit/Consultant%20Directory";

//redirect to the constructed URL
header ("Location: $url");

?> 

(a) would this code work?
(b) how do you get this code to be evaluated in the header? (I assume this might have something to do with themes. :)

Thoughts welcome

David Geilhufe
Social Source Foundation
Try CiviCRM http://www.openngo.org/

Dublin Drupaller’s picture

Hi David,

I'm not sure if that php will work..

Did you have a look at the snippet to Insert user friendly "click here to add your.." links when user profile fields are left blank?

it's a php snippet that could be adapted for a menu block. It also has an added check..i.e.

1. checks to see if the user is online and is the same user
2. checks to see if the user has permission to edit profiles

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

dgeilhufe@yahoo.com’s picture

Low and behold, drupal provides a function :)

<?php
drupal_goto("user/$user->uid/edit/Consultant%20Directory")
?>

This redirects me quite nicely to
user//edit/Consultant%20Directory

You will notice the double // indicates it will not print the userID.

I'm sure this is painfully obvious, but my php skills are on day 3 or 4 :)

Any thoughts appreciated.

David Geilhufe
Social Source Foundation
Try CiviCRM http://www.openngo.org/

dgeilhufe@yahoo.com’s picture

<?php 
global $user; 
if ($user->uid) 
{ drupal_goto("user/$user->uid/edit/Consultant%20Directory​"); }
?>

To register for the consultant directory, you must be logged in.

Apparently, the price of this answer is that I need to talk badly about Morbus.

The guys on #dupal-support on chat.freenode.net are not as scary as you might think.

David Geilhufe
Social Source Foundation
Try CiviCRM http://www.openngo.org/

Dublin Drupaller’s picture

Hi David,

For other users reading this, what David posted is a redirect not a link.

A menu link will look something like this:

global $user;
if ($user->uid) {
print "<a href=\"user/$user->uid/edit/Consultant%20Directory\">click here</a>";
}

notes: Where "/Consultant%20Directory" is the name of the profile category you want to link the user to....a more advanced set of links is available in the user profile snippets section of the handbook.

the above could be added to a menu, block or php page..

hope that helps..

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

nevets’s picture

So the code will work with or wiith out clean urls change

print "<a href=\"user/$user->uid/edit/Consultant%20Directory\">click here</a>";

to

print l('click here', "user/$user->uid/edit/Consultant%20Directory");
dgeilhufe@yahoo.com’s picture

thanks, nevets!

David Geilhufe
Social Source Foundation
Try CiviCRM http://www.civicrm.org/

Matt B’s picture

I tried a similar piece of code to put a 'My nofiications' link to the notficiations tab on the user page. To access this page the path is formed as 'user/{uid}/notify}'. I set the page up with the following code:

global $user;
if ($user->uid)
{ drupal_goto("user/$user->uid/notify​"); }

When I navigate to the page, it puts http://www.example.com/user/2/notify (for example) in the location bar, but actually displays the account view page (normally http://www.example.com/user/2). However if I manually type 'http://www.example.com/user/2/notify' into the location bar of the browser, the correct tab is displayed. Can't figure out why this doesn't work!

(drupal 6.4 with the notify module)

Matt

Matt B’s picture

adding a trailing / works...

<?php
global $user;
if ($user->uid)
{ drupal_goto("user/$user->uid/notify/"); }
?>
.kuma’s picture

Does anyone else notice the cron errors that pop up after using the edit link?

When I run cron, I end up at user id 1's edit profile page (maybe because I'm logged in as user 1, I'm not sure) and get about 40 errors in my log that look like:

LAST
error php	10/27/2008 - 14:09	require_once(./sites/all/modules/cck/theme/theme ...	root	
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/user/user.admin.inc) [<a ...	root	
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/user/user.admin.inc) [<a ...	root	
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/user/user.admin.inc) [<a ...	root	
.
.
.
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/aggregator/aggregator.pages ...	root	
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/aggregator/aggregator.pages ...	root	
error	php	10/27/2008 - 14:09	include_once() [<a ...	root	
error	php	10/27/2008 - 14:09	include_once(modules/aggregator/aggregator.pages ...	
FIRST

Thanks!

mittalpatel’s picture

For this, I installed 'me' aliases module and it worked nicely for me.
I could use user/me/edit for Edit Profile menu.

Though the problem I am facing is that as soon as I enable 'me' aliases module. The Edit profile page doesn't show extra fields I have created using profile module :(. It just shows Account Information. ( I created more profile fields under Personal Information, but it doesn't show up while 'me' is enabled.)

I think 'me' aliases is interfering with it because if I disable it then edit profile will show all the fields.

- Mitsss
http://www.MittalPatel.co.in

patcon’s picture

In case anyone else stumbles upon this with the same problem as the initial poster, try Menu Token (http://drupal.org/project/menu_token)

Barrett’s picture

...which would be awesome if only it had a d6 release.

artscoop’s picture

Hi,

You can provide a user link to your profile edit page easily but you need a module to do so.
You have to register a menu item for the path 'user/edit' (this is a path one would expect, in the way of /user)
The callback function would then redirect to user/$user->uid/edit.

/**================================
Add a path for the user edit form
- the path is user/edit
=================================*/
function mymod_menu () {
  $items ['user/edit'] = array (
    'title' => 'Edit profile',
    'page callback' => 'mymod_redirect_user_edit',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

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

Buckminster_Bond’s picture

Missed the fact that this was D6 - can confirm it doesn't work on D7!