3 namespace Drupal\Core\Render\Element;
5 use Drupal\Core\Render\Element;
8 * Provides a form element for entering a telephone number.
10 * Provides an HTML5 input element with type of "tel". It provides no special
14 * - #size: The size of the input element in characters.
15 * - #pattern: A string for the native HTML5 pattern attribute.
19 * $form['phone'] = array(
21 * '#title' => $this->t('Phone'),
22 * '#pattern' => '[^\d]*',
26 * @see \Drupal\Core\Render\Element
30 class Tel extends FormElement {
35 public function getInfo() {
36 $class = get_class($this);
41 '#autocomplete_route_name' => FALSE,
43 [$class, 'processAutocomplete'],
44 [$class, 'processAjaxForm'],
45 [$class, 'processPattern'],
48 [$class, 'preRenderTel'],
50 '#theme' => 'input__tel',
51 '#theme_wrappers' => ['form_element'],
56 * Prepares a #type 'tel' render element for input.html.twig.
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.
64 * The $element with prepared variables ready for input.html.twig.
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']);