Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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  * - #pattern: A string for the native HTML5 pattern attribute.
16  *
17  * Usage example:
18  * @code
19  * $form['phone'] = array(
20  *   '#type' => 'tel',
21  *   '#title' => $this->t('Phone'),
22  *   '#pattern' => '[^\d]*',
23  * );
24  * @endcode
25  *
26  * @see \Drupal\Core\Render\Element
27  *
28  * @FormElement("tel")
29  */
30 class Tel extends FormElement {
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getInfo() {
36     $class = get_class($this);
37     return [
38       '#input' => TRUE,
39       '#size' => 30,
40       '#maxlength' => 128,
41       '#autocomplete_route_name' => FALSE,
42       '#process' => [
43         [$class, 'processAutocomplete'],
44         [$class, 'processAjaxForm'],
45         [$class, 'processPattern'],
46       ],
47       '#pre_render' => [
48         [$class, 'preRenderTel'],
49       ],
50       '#theme' => 'input__tel',
51       '#theme_wrappers' => ['form_element'],
52     ];
53   }
54
55   /**
56    * Prepares a #type 'tel' render element for input.html.twig.
57    *
58    * @param array $element
59    *   An associative array containing the properties of the element.
60    *   Properties used: #title, #value, #description, #size, #maxlength,
61    *   #placeholder, #required, #attributes.
62    *
63    * @return array
64    *   The $element with prepared variables ready for input.html.twig.
65    */
66   public static function preRenderTel($element) {
67     $element['#attributes']['type'] = 'tel';
68     Element::setAttributes($element, ['id', 'name', 'value', 'size', 'maxlength', 'placeholder']);
69     static::setAttributes($element, ['form-tel']);
70
71     return $element;
72   }
73
74 }