Say I have the path widget/123
to view a widget, and have another path to edit some properties of this widget at admin/acme/widget/123/edit
. In hook_menu
it looks like I can still have the admin path appear as a local task (tab) by setting the tab_parent
and tab_root
properties in hook_menu()
, but I can't seem to get it to work. I know how to setup widget/%/edit
as a local task, but in this case I'm only interested in setting a different "root" path as a local task.
Here's my code:
<?php
function acme_menu() {
// View a widget.
$items['widget/%'] = array(
'type' => MENU_CALLBACK,
'page callback' => 'acme_widget_view',
'page arguments' => array(1),
'access callback' => 'acme_widget_access',
'access arguments' => array(1, 'view'),
'file' => 'includes/widget.view.inc',
);
// Edit a widget.
$items['admin/acme/widget/%/edit'] = array(
'type' => MENU_LOCAL_TASK,
'tab_parent' => 'widget/%',
'tab_root' => 'widget/%',
'title' => 'Edit Widget',
'page callback' => 'drupal_get_form',
'page arguments' => array('acme_widget_edit', 3),
'access callback' => 'acme_widget_access',
'access arguments' => array(1, 'edit'),
'file' => 'includes/widget.edit.inc',
);
return $items;
}
?>
Am I misunderstanding tab_parent/root, or can this be done?
Update: I was missing a MENU_DEFAULT_LOCAK_TASK
. Adding
$items['widget/%/view'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => 'View'
);
allows the tabs to appear. However, they don't share the same argument position and so the argument (the widget ID) isn't passed between the two. The 'Edit' tab, for example, links to admin/acme/widget//edit
. Is there a way to have different routes like this and pass the argument position around?
$items['widget/%/view']
as well, which is aMENU_DEFAULT_LOCAL_TASK
, and becomes a sibling of the otherMENU_LOCAL_TASK
s under the same parent. At the moment I think the fact you've only got a single local task under the parent means that none will show$items['widget/%/view'] = array('type' => MENU_DEFAULT_LOCAL_TASK, 'title' => 'View');
. If you post your comment as an answer I'll accept it.