Is there a way to override other modules paths from the module I am developing?

For example, in Ubercart, you have the user order page under user/%/orders.

Is there a way to change this path without modifying the ubercart order module?

Basically I would like to leave only profile view and profile edit under the user/ path and put all other user related stuff under dashboard/

I haven't found a way yet to do so. Any help is welcome!

Comments

shyamala’s picture

Use the function path_set_alias.

Aibu’s picture

Hi Shyamala,
thanks for pointing me to the right direction.

This is working fine, but unfortunately, even if the path is different, the page is shown inside the user profile section of the site (and as a tab of the user section).

What I would like to achieve is to completely remove orders from the user section and call it from some other places. For what I have seen, this is not possible, unless I modify the order module (which is something I would like to avoid).

I would be happy if you could tell me I am wrong!

Thanks a lot!

shyamala’s picture

What you want is not just to change the path but also to reset some of the menucallback's properties. You can do this by using Hook Menu Alter.

function my_module_menu_alter(&$items) {
 $items['user/...']['type'] = MENU_CALLBACK;
}

i.e you are now changing the type of Menu callback user/... from MENU_LOCAL_TASK to a regular MENU_CALLBACK. This callback will no longer be displayed in a tab.

Aibu’s picture

Thanks again,
but no success...

If I use the hook menu_alter, drupal says to me that I have no access to the page:

function my_module_menu_alter(&$items) {
 $items['user/%/orders']['type'] = MENU_CALLBACK;
}

then I tried with:

function my_module_menu_alter(&$items) {
 $alias = 'dashboard/'.$user->uid.'/orders';
 path_set_alias('user/'.$user->uid.'/orders', $alias);
 $items['user/%/orders']['link_path'] = 'dashboard/%/orders';
}

but I still receive an access error...

But for sure the information you gave me are correct. I will try to explore and learn a bit more.

Thanks a lot!

Aibu’s picture

Solved, thanks a lot!

The issue was on declaring the wild card.

Instead of:

function my_module_menu_alter(&$items) {
 $items['user/%/orders']['link_path'] = 'dashboard/%/orders';
}

I had to use:

function my_module_menu_alter(&$items) {
 $items['user/%user/orders']['link_path'] = 'dashboard/%user/orders';
}

changing % to %user as explained here:
http://drupal.org/node/483324

Thank you!

socialnicheguru’s picture

thanks this was helpful.

Did it allow you to print what was at user/%user/orders to your new path with the content appropriately themed?

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.