I'm relatively new to Drupal and have created a module that among other things uses hook_menu() to add a link to a user navigation "my gallery" this all works well except this link appears when a user views another user's profile. So what i want to do is add some code to tell Drupal not to display this link when a user is not on their own profile.
I'm guessing I need to change the access callback from user_access to a custom callback that carries out this check. Any help would be greatly appreicated.
EDIT my code so far is
global $user;
//get name of current user
$currentUser = $user->uid;
//get profile url
$profileUrl = arg(1);
// compare usernames to determine whether the user is on their own profile.
if($currentUser == $profileUrl)
{
//user is on their profile, display link
$profileUrl = "i'm home";
}
else
{
$profileUrl = "away";
}
$items['user/%user/gallery'] = array(
'title' => $profileUrl
,'page callback' => 'drupal_goto'
,'page arguments' => array('gallery')
,'access callback' => 'user_access'
,'access arguments' => array('access content')
,'type' => MENU_LOCAL_TASK
);
return $items;
The problem is it seems to get fixated, so if i start on the admin profile it correctly displays i'm home, however if i view another profile this doesn't change as it should. ANy ideas?
EDIT 2 Thanks mohit_rocks, your idea of using the title callback helped me get to the answer. For those interested I set up an access callback to perform the check dynamically.
$user. You can then compare that to the url. if they are the same then you are viewing your own profile. – austin Jan 10 at 20:55