Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By TWD on
I have a module which creates custom tabs on the User Profile page.
Problem is that these tabs will show up on every profile page.
I ONLY want them to appear on the currently logged in user's own profile page.
Any suggestions how to do that?
/**
* Implements hook_menu().
*/
function customusertabs_menu() {
$items['user/%user/add-customevent'] = array(
'title' => 'Add Custom Event',
'page callback' => 'drupal_goto',
'page arguments' => array('node/add/event-calendar'),
'access callback' => 'user_access',
'access arguments' => array('create event_calendar content'),
'type' => MENU_LOCAL_TASK,
);
$items['user/%user/helpdesk_support'] = array(
'title' => 'Support Tickets',
'page callback' => 'drupal_goto',
'page arguments' => array('support/helpdesk_support'),
'access callback' => 'user_access',
'access arguments' => array('create support_ticket content'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
Comments
Hi TWD,
Hi TWD,
You would probably want a custom access function that checks the current user is the user id in the url.
This is untested but may give you a direction to head:
As an example, change
As an example, change
to
and add
which only allows access if the user is the owner of the account and they have the appropriate permission.
Thanks for the feedback from
Thanks for the feedback from both of you.
Still having trouble with this though.
This is a simplified version that I expect to work but doesn't.
It doesn't show the custom user tab for ANY profile although I expected it to appear for the logged in user's OWN profile.
I am leaving hook_permissions out of this for the moment to keep it simple.
Any thoughts? Is it a problem of data type mismatch here:
if ($account->uid == $userID)
percent arguments like %user
percent arguments like %user are special, in this case the uid in the path is converted to a user object, so that is what is passed to the function, not a uid. It is why I called the argument $account and used the global $user in my example.
Bingo !!
Bingo !!
This works now.
Thanks a bunch.
I'll need to add some Admin level permission but that looks straight forward.
cheers.