Textarea.php

Same filename in this branch
  1. 11.x core/modules/config_translation/src/FormElement/Textarea.php
Same filename in other branches
  1. 9 core/modules/config_translation/src/FormElement/Textarea.php
  2. 9 core/lib/Drupal/Core/Render/Element/Textarea.php
  3. 8.9.x core/modules/config_translation/src/FormElement/Textarea.php
  4. 8.9.x core/lib/Drupal/Core/Render/Element/Textarea.php
  5. 10 core/modules/config_translation/src/FormElement/Textarea.php
  6. 10 core/lib/Drupal/Core/Render/Element/Textarea.php

Namespace

Drupal\Core\Render\Element

File

core/lib/Drupal/Core/Render/Element/Textarea.php

View source
<?php

namespace Drupal\Core\Render\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Attribute\FormElement;

/**
 * Provides a form element for input of multiple-line text.
 *
 * Properties:
 * - #rows: Number of rows in the text box.
 * - #cols: Number of columns in the text box.
 * - #resizable: Controls whether the text area is resizable.  Allowed values
 *   are "none", "vertical", "horizontal", or "both" (defaults to "vertical").
 * - #maxlength: The maximum amount of characters to accept as input.
 *
 * Usage example:
 * @code
 * $form['text'] = [
 *   '#type' => 'textarea',
 *   '#title' => $this->t('Text'),
 * ];
 * @endcode
 *
 * @see \Drupal\Core\Render\Element\Textfield
 * @see \Drupal\filter\Element\TextFormat
 */
class Textarea extends FormElementBase {
    
    /**
     * {@inheritdoc}
     */
    public function getInfo() {
        $class = static::class;
        return [
            '#input' => TRUE,
            '#cols' => 60,
            '#rows' => 5,
            '#resizable' => 'vertical',
            '#process' => [
                [
                    $class,
                    'processAjaxForm',
                ],
                [
                    $class,
                    'processGroup',
                ],
            ],
            '#pre_render' => [
                [
                    $class,
                    'preRenderGroup',
                ],
            ],
            '#theme' => 'textarea',
            '#theme_wrappers' => [
                'form_element',
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
        if ($input !== FALSE && $input !== NULL) {
            // This should be a string, but allow other scalars since they might be
            // valid input in programmatic form submissions.
            return is_scalar($input) ? (string) $input : '';
        }
        return NULL;
    }

}

Classes

Title Deprecated Summary
Textarea Provides a form element for input of multiple-line text.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.