“Add link” in my account menu
Question
The user account page (http://example.com/user) consists of some default tabs like "View," "Edit," etc.
I want to add my menu link over there. The content to be returned should depend on the user ID. How do I do this?
Solution
If you just want to add a new tab, then the module should just implement hook_menu(), using code similar to the following.
function mymodule_menu() {
$items = array();
$items['user/%user/new_tab'] = array(
'title' => 'New tab title',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_newtab_form', 1),
'access arguments' => array('access new tab'),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function mymodule_newtab_form($form, &$form_state, $account) {
// ...
}
mymodule_newtab_form()
would get the user object in $account
. That menu callback would build a form using the form API. If the purpose is to output, the menu callback declaration would be similar, except two array indexes, which would be:
'page callback' => 'mymodule_newtab_form',
'page arguments' => array(1),
The argument passed to the callback would be different too.
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange