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'
);

items['parent/tab1'] = array(
  'title' => 'I am the first tab',
  'type' => MENU_DEFAULT_LOCAL_TASK,
);

items['parent/tab2'] = array(
  'title' => 'I am the 2nd tab',
  'type' => MENU_LOCAL_TASK,
  'page callback' => 'mymodule_page2_callback'
);

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'
);

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 2nd tab',
  'type' => MENU_LOCAL_TASK,
  'page callback' => 'mymodule_page2_callback'
  '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

CommentFileSizeAuthor
#1 menu.inc_.zip36.04 KBkjholla

Comments

kjholla’s picture

StatusFileSize
new36.04 KB

An update:

I hacked around with the code in menu.inc and finally seem to have got this working for Scenario 2 that I described earlier.

Attached is a basic patch of the changes I made along with the modified menu.inc file.

Please note that this is a hack. The objective of uploading these files is only to illustrate the issue further and to provide my inputs on what I think will fix it.

Thanks,
KH

regginos’s picture

Issue summary: View changes

Version: 7.22 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.