9289a1d028ce711b50af325ec196b37504a27bf1
[yaffs-website] / web / core / lib / Drupal / Core / Render / Element / Tel.php
1 <?php
2
3 namespace Drupal\Core\Render\Element;
4
5 use Drupal\Core\Render\Element;
6
7 /**
8  * Provides a form element for entering a telephone number.
9  *
10  * Provides an HTML5 input element with type of "tel". It provides no special
11  * validation.
12  *
13  * Properties:
14  * - #size: The size of the input element in characters.
15  *
16  * Usage example:
17  * @code
18  * $form['phone'] = array(
19  *   '#type' => 'tel',
20  *   '#title' => $this->t('Phone'),
21  * );
22  * @endcode
23  *
24  * @see \Drupal\Core\Render\Element
25  *
26  * @FormElement("tel")
27  */
28 class Tel extends FormElement {
29
30   /**
31    * {@inheritdoc}
32    */
33   public function getInfo() {
34     $class = get_class($this);
35     return [
36       '#input' => TRUE,
37       '#size' => 30,
38       '#maxlength' => 128,
39       '#autocomplete_route_name' => FALSE,
40       '#process' => [
41         [$class, 'processAutocomplete'],
42         [$class, 'processAjaxForm'],
43         [$class, 'processPattern'],
44       ],
45       '#pre_render' => [
46         [$class, 'preRenderTel'],
47       ],
48       '#theme' => 'input__tel',
49       '#theme_wrappers' => ['form_element'],
50     ];
51   }
52
53   /**
54    * Prepares a #type 'tel' render element for input.html.twig.
55    *
56    * @param array $element
57    *   An associative array containing the properties of the element.
58    *   Properties used: #title, #value, #description, #size, #maxlength,
59    *   #placeholder, #required, #attributes.
60    *
61    * @return array
62    *   The $element with prepared variables ready for input.html.twig.
63    */
64   public static function preRenderTel($element) {
65     $element['#attributes']['type'] = 'tel';
66     Element::setAttributes($element, ['id', 'name', 'value', 'size', 'maxlength', 'placeholder']);
67     static::setAttributes($element, ['form-tel']);
68
69     return $element;
70   }
71
72 }