Added another front page space for Yaffs info. Added roave security for composer.
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Textfield.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Render\Element;
7
8 /**
9  * Provides a one-line text field form element.
10  *
11  * Properties:
12  * - #maxlength: Maximum number of characters of input allowed.
13  * - #size: The size of the input element in characters.
14  * - #autocomplete_route_name: A route to be used as callback URL by the
15  *   autocomplete JavaScript library.
16  * - #autocomplete_route_parameters: An array of parameters to be used in
17  *   conjunction with the route name.
18  *
19  * Usage example:
20  * @code
21  * $form['title'] = array(
22  *   '#type' => 'textfield',
23  *   '#title' => $this->t('Subject'),
24  *   '#default_value' => $node->title,
25  *   '#size' => 60,
26  *   '#maxlength' => 128,
27  * '#required' => TRUE,
28  * );
29  * @endcode
30  *
31  * @see \Drupal\Core\Render\Element\Color
32  * @see \Drupal\Core\Render\Element\Email
33  * @see \Drupal\Core\Render\Element\MachineName
34  * @see \Drupal\Core\Render\Element\Number
35  * @see \Drupal\Core\Render\Element\Password
36  * @see \Drupal\Core\Render\Element\PasswordConfirm
37  * @see \Drupal\Core\Render\Element\Range
38  * @see \Drupal\Core\Render\Element\Tel
39  * @see \Drupal\Core\Render\Element\Url
40  *
41  * @FormElement("textfield")
42  */
43 class Textfield extends FormElement {
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getInfo() {
49     $class = get_class($this);
50     return [
51       '#input' => TRUE,
52       '#size' => 60,
53       '#maxlength' => 128,
54       '#autocomplete_route_name' => FALSE,
55       '#process' => [
56         [$class, 'processAutocomplete'],
57         [$class, 'processAjaxForm'],
58         [$class, 'processPattern'],
59         [$class, 'processGroup'],
60       ],
61       '#pre_render' => [
62         [$class, 'preRenderTextfield'],
63         [$class, 'preRenderGroup'],
64       ],
65       '#theme' => 'input__textfield',
66       '#theme_wrappers' => ['form_element'],
67     ];
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
74     if ($input !== FALSE && $input !== NULL) {
75       // This should be a string, but allow other scalars since they might be
76       // valid input in programmatic form submissions.
77       if (!is_scalar($input)) {
78         $input = '';
79       }
80       return str_replace(["\r", "\n"], '', $input);
81     }
82     return NULL;
83   }
84
85   /**
86    * Prepares a #type 'textfield' render element for input.html.twig.
87    *
88    * @param array $element
89    *   An associative array containing the properties of the element.
90    *   Properties used: #title, #value, #description, #size, #maxlength,
91    *   #placeholder, #required, #attributes.
92    *
93    * @return array
94    *   The $element with prepared variables ready for input.html.twig.
95    */
96   public static function preRenderTextfield($element) {
97     $element['#attributes']['type'] = 'text';
98     Element::setAttributes($element, ['id', 'name', 'value', 'size', 'maxlength', 'placeholder']);
99     static::setAttributes($element, ['form-text']);
100
101     return $element;
102   }
103
104 }