views:

83

answers:

2

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.

A: 

It's in menus. The menu you want to edit is called Primary links as far as I remember.

ALSO the tabs show up when You fill in one field when creating an article, so to remove such a link You have to click it, click edit in the article and unfold the "menu link" part and clear the fields there or edit.

naugtur
I don't see them in menus. These aren't in navigation, primary, or secondary. I'm using the array-shift installation profile of drupal, and it has a few custom site tweaks that I thought might have created this list of tabs, but I didn't see that anywhere in the template.php file or in the as_tweaks module. About the articles, I've checked all the content types that exist in my site and I don't see any that have a menu settings being a child of the user profile link. Is there somewhere else I can look?
Dylan West
+1  A: 

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.

Mark Trapp
I will check out this method tomorrow and let you know if it worked. Thanks!
Dylan West
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.
Mark Trapp
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
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.
Mark Trapp