I have noticed that if I define tabs (MENU_DEFAULT_LOCAL_TASK and MENU_LOCAL_TASK) using totally paths that are not sub-paths of the parent path, then the tabs don't inherit the access callback or the name of the parent.
Let me explain:
Typically, I would have a MENU_NORMAL_ITEM and then a MENU_DEFAULT_LOCAL_TASK directly under it.
This is Scenario 1, which we are all familiar with:
items['parent'] = array(
'title' => 'I am the parent',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'mymodule_page_callback'
'access callback' => 'mymodule_access_callback',
'access arguments' => array('access tabs'),
);
items['parent/tab1'] = array(
'title' => 'I am the first tab',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
items['parent/tab2'] = array(
'title' => 'I am the parent',
'type' => MENU_LOCAL_TASK,
'page callback' => 'mymodule_page2_callback'
'access callback' => 'mymodule_access_callback',
'access arguments' => array('access tab2'),
);
The above scenario works great. All is well and the tabs work fine.
However, I can also define a set of tabs using the tab_parent and tab_root attributes of the menu item.
Scenario 2: I can define a menu with the parent and its children having different paths altogether and then use the tab_parent and tab_root properties to define the parent:
Something as below.
items['parent'] = array(
'title' => 'I am the parent',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'mymodule_page_callback'
'access callback' => 'mymodule_access_callback',
'access arguments' => array('access tabs'),
);
items['tab1'] = array(
'title' => 'I am the first tab',
'type' => MENU_DEFAULT_LOCAL_TASK,
'tab_parent' => 'parent',
'tab_root' => 'parent',
);
items['tab2'] = array(
'title' => 'I am the parent',
'type' => MENU_LOCAL_TASK,
'page callback' => 'mymodule_page2_callback'
'access callback' => 'mymodule_access_callback',
'access arguments' => array('access tab2'),
'tab_parent' => 'parent',
'tab_root' => 'parent',
);
I notice that the default local task does not inherit the access callback of the parent in the second scenario. Also, none of the children seem to inherit the name of the parent menu item.
I investigated this by looking through includes/menu.inc
among the Drupal core files and believe that this may be something to do with what's happening within the function _menu_router_build
. In line# 3633 the parent path of the menu item is derived from the individual parts of the original path. However, if the paths are different as illustrated above, this approach will not work. We will need to also check if the item has a 'tab_parent' defined and take that as the parent path if it is set.
Request the Drupal experts to review this and provide feedback and possibly a fix.
Regards,
KH