0

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 ?

enter image description here

  • Did you clear the cache? This look like old stuff is still hanging around. – BetaRide Jan 16 '12 at 6:58
  • Yes, I did clear the cache, but still see the errors. – Sithu Jan 16 '12 at 7:56
  • Post the leg_node_form function. Are all of these in the same .module file? – drewish Jan 18 '12 at 3:05
  • I think there is no leg_node_form function. It is just a form id to the drupal node form infrastructure in the form of {contenttype}_node_form. – Sithu Jan 18 '12 at 3:42
1

The problem is not your hook_menu implementation, but your function leg_node_form. That function probably calles node_form, which is in file modules/node/node.pages.inc you have to include that file manually using module_load_include.

  • After I added this : function mymodule_init(){ module_load_include('inc', 'node', 'node.pages'); }. I got this error : Fatal error: Cannot access empty property in C:\xampp\htdocs\mysite\modules\field\field.attach.inc on line 197 – Sithu Jan 17 '12 at 3:44
  • I see this issue at drupal.org/node/947748, but they are saying about media module and drupal beta verson. I have no media module and my drupal is 7.7. – Sithu Jan 17 '12 at 3:45
  • A better place to include node.pages.inc would be the function that calls node_form (I suspect this is mymodule_leg_select_form). Also, if the error is in function mymodule_leg_select_form, show us this function. – Oswald Jan 17 '12 at 10:38
  • I updated my original post with the code for mymodule_leg_select_form, but it is called by menu default local task. I got the error only when I navigate to the second tab. I tried to add 'file' and 'file path' to node.pages.inc in the menu registration "leg/add". But still see the error : Fatal error: Cannot access empty property in path\to\site\modules\field\field.attach.inc on line 197. I have two fields for the content type leg - field_from and field_to and hided title and body field. – Sithu Jan 18 '12 at 2:50
  • Sorry, I got confused. I suspect the error is in leg_node_form. – Oswald Jan 18 '12 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.