Reordering fields in a form
The Form API, like many other components of Drupal, provides options to order form elements through the use of weights. In this recipe, we will exercise this feature to reorder fields in a typical node form with the aim of giving greater prominence to the body field and less to the menu and category fields.
Getting ready
We will be using the mysite module created earlier in this book to contain our hook_form_alter()
. It is also recommended that the Devel module be enabled to help with diagnostic prints and other debugging efforts.
How to do it...
Navigate to the mysite module folder at sites/all/modules/mysite
to perform the following steps:
Locate the file
mysite.module
and open it in an editor.Scroll down to the bottom and add the following function:
/** * Implementation of hook_form_alter(). */ function mysite_form_alter(&$form, &$form_state, $form_id) { // dpm($form_id); // dpm($form); if (isset($form['#node']) && $form['#node']->type .'_node_form...