MENU_DEFAULT_LOCAL_TASK, to_arg, and loaders

tbruce - July 4, 2009 - 13:57

Short version: if you want to use a wildcard to invoke to_arg and loader functions for a default tab (the menu item whose type is MENU_DEFAULT_LOCAL_TASK), how do you do it?

Long version: Suppose we have two menu items, part of a tabbed interface, that start off looking like this:
$items['cfr'] = array(
'title' => 'CFR fragment',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'cfr_main_entry',
'access callback' => TRUE,
);

// main text tab
$items['cfr/text'] = array(
'title' => 'Text',
'type' => MENU_DEFAULT_LOCAL_TASK,
'access callback' => TRUE,
'weight' => 0,
);

It seems (from experimentation) that the page callback has to go in the MENU_NORMAL_ITEM that is acting as the parent for the MENU_DEFAULT_LOCAL_TASK .

a) Is that really true?
b) Suppose that we want to add a to_arg function that will make the "Text" tab have a link of our choosing. Does its wildcard belong in the MENU_DEFAULT_LOCAL_TASK item, or in the parent?
c) Suppose that we also want a load function that will work with the child? Where does its wildcard go?

I've been flailing at this for a while and have the impression that maybe to_arg calls don't work in the child and loader calls don't work in the parent, but at this point I'm so confused I can't really say either way. Documentation and the Pro Drupal Devel book are not helpful on this point.

For a regular MENU_LOCAL_TASK (not the default), it seems not to be a problem:
$items['cfr/authorities/%cfr_auth_tab'] = array(
'title' => 'Statute',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
'page callback' => 'cfr_show_plltable',
'load arguments' => array('%map','%index'),
'access callback' => TRUE,
);

appeared to work fine with cfr_auth_tab_to_arg and cfr_auth_tab_load ... but again, I've been around the block with this many times now and I'm more than a little confused.

 
 

Drupal is a registered trademark of Dries Buytaert.