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