Dallas Clark
Dallas Clark

Reputation: 4112

Drupal: How to modify menu items with hooks?

I need to add the URL 'user/7/orders' to a particular menu. As this requires PHP for the UID (7), how do I write a script to add an item to a particular menu?

Upvotes: 0

Views: 6037

Answers (2)

JarodMS
JarodMS

Reputation: 121

Not sure if I understand your question correctly, but if you need to add that menu for each user and their orders, you could use the Me module (http://drupal.org/project/me) and then create a menu item linking to "user/me/orders".

Upvotes: 1

Amarnath Ravikumar
Amarnath Ravikumar

Reputation: 920

You can use the menu hook for this.

Assuming you have your own custom module on your site, this should work -

function custom_menu() {
  $items = array();
  $items['user/7/orders'] = array(
    'title' => 'My Orders',
    'page callback' => 'custom_order_callback', 
    'access callback' => user_access('access content'), // You can change this
    'type' => MENU_LOCAL_TASK
  }
  return $items;
}

If you want the Orders tab to show up for all users, you can use $items['user/%/orders'] above and get the page arguments to prepare your data.

For the menu type, you can use MENU_CALLBACK, MENU_LOCAL_TASK or MENU_DEFAULT_LOCAL_TASK. Check here to see how they differ.

Upvotes: 2

Related Questions