0
votes

I'm building a travel site. In my site there are 3-4 modules as Tour, Villa, and Hotel etc. In Drupal if we want to add any content of hotel type then we have to go to a link like www.mysite.com/node/add/hotel or for villa www.mysite.com/node/add/villa. I am using a field named 'Render Type' for the both villa and hotel content type. The widget type for the field 'Render Type' is select list. It has values 1,2,3,4. Now I want to write a hook that will allow me to define 'Render Type' field’s value regarding the content type. While adding any hotel, Render type should be auto selected to 1. How can I write the hook?

1

1 Answers

0
votes

You can do this using hook_form_alter.

Example:

YOURMODULE_form_alter(&$form, &$form_state, $form_id){<br/>
    switch ($form_id) {<br/>
      case 'villa-node-form':<br/>
        $form->['field_render_type'][LANGUAGE_NONE]['#options'][1] = "villa option";<br/>
        break;<br/>
      case 'hotel-node-form':<br/>
        $form->['field_render_type'][LANGUAGE_NONE]['#options'][1] = "hotel option";<br/>
        break;<br/>

    }

}