Add a tab to a module edit page
m.gribaudo - March 11, 2008 - 13:03
I'm starting the "hard" part of my first module (WiSoul.module) and I need to split the form of the edit page in two tabs ("Trak" tab & "Waypoints" tab).
Following, but not fully understanding, the following tip http://groups.drupal.org/node/8386, in the hook_menu I put the code :
$items[] = array('path' => 'WiSoul',
'title' => t('WiSoul Track Edit'),
'description' => t('Edit the WiSoul track'),
'access' => user_access('edit own WiSoul'),
'callback' => 'drupal_get_form',
'callback arguments' => array('WiSoul_test')
);
$items[] = array('path' => 'WiSoul/track',
'title' => t('Track'),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items[] = array('path' => 'WiSoul/waypoints',
'title' => t('Waypoints'),
'access' => user_access('edit own WiSoul),
'callback' => 'WiSoul_form_subfolder',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);But I cannot se the tab.
I'm not sure about the path of the menu itmes of the edit page, I also tried "Wisoul/edit", "node/edit" and others with no results.
Where am I wrong?
Thanks
Marcello

You need to set the callback info for WiSoul/track too
Assuming you want the 'Track' tab to display your `WiSoul_test` form, try setting your second $items[] =array to:
$items[] = array('path' => 'WiSoul/track','title' => t('Track'),
'access' => user_access('edit own WiSoul'),
'callback' => 'drupal_get_form',
'callback arguments' => array('WiSoul_test')
'type' => MENU_DEFAULT_LOCAL_TASK,
);
Is this a custom content
Is this a custom content type based on node?
Yes
I 'we also tried something like this
$items[] = array('path' => "node/". arg(1) . "/edit",...
with crazy results
In that case you need something like
In that case you need something like the following. The two key parts are since you are adding a tab to a node the path needs to start with
node/{nid}and the menu item can not be cached since it depends on the current path. So something likefunction your_module_name_menu($may_cache) {
$items = array();
if ($may_cache) {
// Other possible menu items
}
else {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
// Change the following line to reflect your node type
$type = 'mytype';
if ($node->nid && $node->type == $type ) {
$items[] = array('path' => 'node/'. arg(1) .'/waypoints',
'title' => t('Waypoints'),
'access' => user_access('edit own WiSoul'),
'callback' => 'WiSoul_form_subfolder',
'callback arguments' =>array($node)
'weight' => 1,
'type' => MENU_LOCAL_TASK);
}
}
}
return $items;
}
should work. Note is passes the current node as an argument to WiSoul_form_subfolder().
Thank's a lot
It work's perfectly!
But now the page title is changed to "View"
Following your suggestion the tab has been now correctly inserted.
But when I click on that tab, the page title (and in my theme the corresponding title before the node) change from the node name to the value "View" (is the name of the first tab).
How can I manage this problem?
Thanks
Well you should not be
Well you should not be defining a tab labeled 'View' (the node module does). Regardless each tab has an associated callback. The page title by default is the tab title but your callback function can call drupal_set_title() to set has desired.