I have a content type leg and this hook_menu
:
$items['leg'] = array(
'title' => t('Choose Leg'),
'page callback' => 'drupal_get_form',
'access arguments' => array('create leg content'),
'page arguments' => array('mymodule_leg_select_form'),
'type' => MENU_NORMAL_ITEM,
'weight' => 0,
);
$items['leg/select'] = array(
'title' => t('Choose an existing leg'),
'page callback' => 'drupal_get_form',
'access arguments' => array('create leg content'),
'page arguments' => array('mymodule_leg_select_form'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 1,
);
$items['leg/add'] = array(
'title' => t('Create a new leg'),
'page callback' => 'drupal_get_form',
'access arguments' => array('create leg content'),
'page arguments' => array('leg_node_form'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
Here is the code snippet from mymodule_leg_select_form()
which is called as MENU DEFAULT LOCAL TASK :
$form = array();
$result = db_query('SELECT nid, title FROM {node} WHERE type = :type AND status = :status ORDER BY title', array(':type'=>'leg', ':status'=>1));
$options = array();
foreach($result as $row){
$options[$row->nid] = $row->title;
}
$form['leg'] = array(
'#type' => 'select',
'#title' => t('Leg'),
'#options' => $options,
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Ok'),
'#weight' => 1,
);
return $form;
The node form is not rendered correctly as you can see in the screen shot. I have two fields - field_from
and field_to
. They are not rendered in the form. The menu path "leg/select" which is default local task did work and correctly rendered my custom form.
The problem only is to integrate node add form in the second tab.
How can I fix this error ?
leg_node_form
function. It is just a form id to the drupal node form infrastructure in the form of{contenttype}_node_form
.