3 namespace Drupal\Core\Render\Element;
5 use Drupal\Core\Form\FormStateInterface;
8 * Provides a form element for input of multiple-line text.
11 * - #rows: Number of rows in the text box.
12 * - #cols: Number of columns in the text box.
13 * - #resizable: Controls whether the text area is resizable. Allowed values
14 * are "none", "vertical", "horizontal", or "both" (defaults to "vertical").
15 * - #maxlength: The maximum amount of characters to accept as input.
19 * $form['text'] = array(
20 * '#type' => 'textarea',
21 * '#title' => $this->t('Text'),
25 * @see \Drupal\Core\Render\Element\Textfield
26 * @see \Drupal\filter\Element\TextFormat
28 * @FormElement("textarea")
30 class Textarea extends FormElement {
35 public function getInfo() {
36 $class = get_class($this);
41 '#resizable' => 'vertical',
43 [$class, 'processAjaxForm'],
44 [$class, 'processGroup'],
47 [$class, 'preRenderGroup'],
49 '#theme' => 'textarea',
50 '#theme_wrappers' => ['form_element'],
57 public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
58 if ($input !== FALSE && $input !== NULL) {
59 // This should be a string, but allow other scalars since they might be
60 // valid input in programmatic form submissions.
61 return is_scalar($input) ? (string) $input : '';