Changing the height of a textarea
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 which represents the body field in a node form.
Getting ready
We will be using the mysite module created earlier in this book to contain the hook_form_alter()
.
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' == $form_id) { $form['body_field']['body']['#rows'] = 5; } }
If there is a pre-existing implementation of
hook_form_alter()
, the highlighted code above...