Search.php

Same filename in this branch
  1. 11.x core/modules/search/src/Plugin/views/filter/Search.php
  2. 11.x core/modules/search/src/Plugin/views/argument/Search.php
  3. 11.x core/modules/search/src/Attribute/Search.php
Same filename in other branches
  1. 9 core/modules/search/src/Plugin/views/filter/Search.php
  2. 9 core/modules/search/src/Plugin/views/argument/Search.php
  3. 9 core/lib/Drupal/Core/Render/Element/Search.php
  4. 8.9.x core/modules/search/src/Plugin/views/filter/Search.php
  5. 8.9.x core/modules/search/src/Plugin/views/argument/Search.php
  6. 8.9.x core/lib/Drupal/Core/Render/Element/Search.php
  7. 10 core/modules/search/src/Plugin/views/filter/Search.php
  8. 10 core/modules/search/src/Plugin/views/argument/Search.php
  9. 10 core/lib/Drupal/Core/Render/Element/Search.php
  10. 10 core/modules/search/src/Attribute/Search.php

Namespace

Drupal\Core\Render\Element

File

core/lib/Drupal/Core/Render/Element/Search.php

View source
<?php

namespace Drupal\Core\Render\Element;

use Drupal\Core\Render\Attribute\FormElement;
use Drupal\Core\Render\Element;

/**
 * Provides an HTML5 input element with type of "search".
 *
 * Usage example:
 * @code
 * $form['search'] = [
 *   '#type' => 'search',
 *   '#title' => $this->t('Search'),
 * ];
 * @endcode
 *
 * @see \Drupal\Core\Render\Element\Textfield
 */
class Search extends FormElementBase {
    
    /**
     * {@inheritdoc}
     */
    public function getInfo() {
        $class = static::class;
        return [
            '#input' => TRUE,
            '#size' => 60,
            '#maxlength' => 128,
            '#autocomplete_route_name' => FALSE,
            '#process' => [
                [
                    $class,
                    'processAutocomplete',
                ],
                [
                    $class,
                    'processAjaxForm',
                ],
            ],
            '#pre_render' => [
                [
                    $class,
                    'preRenderSearch',
                ],
            ],
            '#theme' => 'input__search',
            '#theme_wrappers' => [
                'form_element',
            ],
        ];
    }
    
    /**
     * Prepares a #type 'search' render element for input.html.twig.
     *
     * @param array $element
     *   An associative array containing the properties of the element.
     *   Properties used: #title, #value, #description, #size, #maxlength,
     *   #placeholder, #required, #attributes.
     *
     * @return array
     *   The $element with prepared variables ready for input.html.twig.
     */
    public static function preRenderSearch($element) {
        $element['#attributes']['type'] = 'search';
        Element::setAttributes($element, [
            'id',
            'name',
            'value',
            'size',
            'maxlength',
            'placeholder',
        ]);
        static::setAttributes($element, [
            'form-search',
        ]);
        return $element;
    }

}

Classes

Title Deprecated Summary
Search Provides an HTML5 input element with type of "search".

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.