340bc114e602f680bf9b7699626418fc592b1220
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Textarea.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 use Drupal\Core\Form\FormStateInterface;
6
7 /**
8  * Provides a form element for input of multiple-line text.
9  *
10  * Properties:
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  *
16  * Usage example:
17  * @code
18  * $form['text'] = array(
19  *   '#type' => 'textarea',
20  *   '#title' => $this->t('Text'),
21  * );
22  * @endcode
23  *
24  * @see \Drupal\Core\Render\Element\Textfield
25  * @see \Drupal\filter\Element\TextFormat
26  *
27  * @FormElement("textarea")
28  */
29 class Textarea extends FormElement {
30
31   /**
32    * {@inheritdoc}
33    */
34   public function getInfo() {
35     $class = get_class($this);
36     return [
37       '#input' => TRUE,
38       '#cols' => 60,
39       '#rows' => 5,
40       '#resizable' => 'vertical',
41       '#process' => [
42         [$class, 'processAjaxForm'],
43         [$class, 'processGroup'],
44       ],
45       '#pre_render' => [
46         [$class, 'preRenderGroup'],
47       ],
48       '#theme' => 'textarea',
49       '#theme_wrappers' => ['form_element'],
50     ];
51   }
52
53   /**
54    * {@inheritdoc}
55    */
56   public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
57     if ($input !== FALSE && $input !== NULL) {
58       // This should be a string, but allow other scalars since they might be
59       // valid input in programmatic form submissions.
60       return is_scalar($input) ? (string) $input : '';
61     }
62     return NULL;
63   }
64
65 }