4

How do I edit link tabs found on the default user profile page in drupal? I'm trying to avoid having to create a user_profile.tpl.php file and rebuild the entire profile from scratch. If there's an easier way to do this, I'd rather do that. But, if I'm forced to create a custom template, how do I control the menu tabs for the profile? I haven't found any documentation that explains that part yet.

Dylan West
  • 627
  • 10
  • 22

2 Answers2

2

Edit

I didn't catch that you wanted to do generic modification of the user profile tabs, not necessarily removing them. I've modified my code to provide a few different examples of how you can modify the tabs.

Edit 2

Removed the user_access() check on the unset as it would only be checked during the menu rebuild. Added access callback example instead.


You can do this in a custom module with hook_menu_alter() and unset():

function mymodule_menu_alter(&$items) {
  // If you have the Devel module installed, uncomment to retrieve list
  // of registered menu items to figure out what to unset.
  // kpr($items);

  // Change the name of the Edit tab
  $items['user/%user_category/edit']['title'] = t('Awesome edit!');

  // Disable the user edit tab, but don't disable the page if you go navigate 
  // directly to it
  // @see http://api.drupal.org/api/function/hook_menu/6 for other types
  $items['user/%user_category/edit']['type'] = MENU_CALLBACK;

  // Only allow people with administer site configuration permissions to
  // access the user edit and user edit account tabs.
  $items['user/%user_category/edit']['access callback'] = 'user_access';
  $items['user/%user_category/edit']['access arguments'] = array('administer site configuration');
  $items['user/%user_category/edit/account']['access callback'] = 'user_access';
  $items['user/%user_category/edit/account']['access arguments'] = array('administer site configuration');

  // Completely disable the user edit tab, even if you go directly to it
  // This affects all users, including user 1.
  unset($items['user/%user_category/edit']);
  unset($items['user/%user_category/edit/account']);
}

Each menu item is registered with Drupal using the $items array. After enabling this module, rebuild the cache and the tabs should be modified.

  • I will check out this method tomorrow and let you know if it worked. Thanks! – Dylan West Aug 02 '10 at 23:35
  • I didn't catch that you wanted to do any modification to the tabs, not necessarily removing them entirely. I updated my code to give you a few more possibilities. –  Aug 03 '10 at 06:59
  • I've noticed a problem with this code. The only time this function seems to be called is when you resubmit the modules from the admin pages. After that, this is not called again. And because you can't resubmit the modules without having administer site configuration permissions, the unset function will never be called. But, I removed the if statement and it worked fine. In my case, it's okay for the admin to not see or access this particular menu item because it is truly a useless menu item. Thank you very much! There must be a way to still get the if statement to work, though. – Dylan West Aug 03 '10 at 14:55
  • Dylan: it's actually only called when the menu is rebuilt, which is when the modules are reloaded, the cache is cleared, or something else triggers a menu rebuild. I don't know what I was thinking with the `if(user_access())` check; I've added the correct way to check permissions as another example before `unset()`. Using `unset()` will disable the page for everyone as Drupal will no longer know about the page. –  Aug 03 '10 at 16:07
1

You can use the Tab Tamer module for editing Drupal's default link tabs that appear in user profile pages.

Nadeem Khan
  • 3,408
  • 1
  • 30
  • 41