I'm using the content profile module. When a user is on their view profile page and press edit, they expect the profile edit page to show, not account settings as it is now. The path to content profile edit page is 'user/%/edit/uprofile'. Does anyone know how to set the 'user/%/edit/uprofile' to default tab for 'user/%/edit'?
Drupal - Set 'user/%/edit/uprofile' to default tab on 'user/%/edit'
5.1k views Asked by Toxid At
4
There are 4 answers
0
On
I was searching for a solution but wasn't satisfied with such complexity. I did it like this.
function MYTHEME_menu_link(array $variables) {
global $user;
if($variables["element"]["#theme"] == "menu_link__user_menu" && $variables["element"]["#original_link"]["router_path"] == "user") {
$variables["element"]["#href"] = "user/".$user->uid."/edit";
}
return theme_menu_link($variables);
}
0
On
Here's the code that worked for me with content profile installed and the default content type ('profile'):
function mymodule_menu_alter(&$items) {
// Save the data from user/%/edit into user/%/edit/account.
$items['user/%user_category/edit/account'] = $items['user/%user_category/edit'];
$items['user/%user_category/edit/account']['tab_parent'] = 'user/%/edit';
$items['user/%user_category/edit/account']['title'] = 'Account';
// Change the default user/%/edit to user/%/edit/profile.
$useredit = &$items['user/%user_category/edit'];
$userprofile = &$items['user/%user_category/edit/profile'];
$useredit['page callback'] = $userprofile['page callback'];
$useredit['page arguments'] = $userprofile['page arguments'];
$useredit['access callback'] = $userprofile['access callback'];
$useredit['access arguments'] = $userprofile['access arguments'];
$useredit['file'] = $userprofile['file'];
$useredit['file path'] = $userprofile['file path'];
// Make the user/%/edit/profile sub-tab the default and left-most sub-tab.
$userprofile['type'] = MENU_DEFAULT_LOCAL_TASK;
$userprofile['weight'] = -10;
}
Change $userprofile = $items['user/%user_category/edit/profile']
to match the content profile path you need (in your case this would be $userprofile = $items['user/%user_category/edit/uprofile']
Also make sure your module runs after the content_profile module (your module must have a 'higher' weight than -1, which is content_profile.module's weight). Modules have a default weight of 0 so you should be fine there.
Edit 2 (for Content Profile)
This example is for a Content Profile tab. Just change
$type
to the short name of the content type for the profile. This also shows how to clean up the code for real-world use (my previous examples were really, really verbose):Edit 1 (for Core's Profile module)
I didn't realize you wanted to change the default tabs under Edit. It's the same general principle as I described below, but with some minor modifications. This example will make the Personal tab (at
user/<UID>/edit/Personal
) default instead of the account tab:Overview and Concept
You can do this with
hook_menu_alter
and changing the types for specific tabs.Changing the default tab is a little bit of a harrowing process. Basically, the default tab inherits all the properties of the page without any tabs selected. This allows a user to go to
user/UID
and get the view page without having to go directly touser/UID/view
.To get a clearer understanding of this, check out the
user_menu()
hook implementation. Note how$items['user/%user/view']
is pretty empty, and$items['user/%user_uid_optional']
contains all the settings you would've expected to see under$items['user/%user/view']
.So, you're going to first set up the view tab to act as a regular tab: to do this, you're going to have to copy all the settings that are attached to the
user/UID
menu item and put them into theuser/UID/view
menu item.Once you do that, you're going to replace the settings for
user/UID
with the settings for the tab you want to become the default tab.Finally, you're going to unset all the menu items for the default tab since it will inherit the settings for
user/UID
.Check out this code which makes the Edit tab default:
Replace the second part of the function with the settings for your menu item and you should be in good shape. Of course, remember to clear the cache after making any menu changes for them to take effect.