Forms in Drupal are managed using the Form API and modified using hook_form_alter()
. In this recipe, we will look at changing the default height, or to be more precise, the default number of rows of the textarea that represents the body field in a node form.
We will be using the mysite module created earlier in this book to contain the hook_form_alter()
.
Navigate to the mysite module folder at sites/all/modules/mysite
to perform the following steps:
1. Locate the file
mysite.module
and open it in an editor.2. Scroll down to the bottom and add the following function:
/** * Implements hook_form_alter(). */ function mysite_form_alter(&$form, &$form_state, $form_id) { // dpm($form_id); // dpm($form); if (isset($form['#node_edit_form'])) { $form['body'][$form['language']['#value']][0]['#rows'] = 5; } }
If there is a pre-existing implementation of
hook_form_alter()
, the highlighted code above will need to be integrated with...