You are here

public function Search::validateExposed in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/search/src/Plugin/views/filter/Search.php \Drupal\search\Plugin\views\filter\Search::validateExposed()

Validate the exposed handler form

Overrides HandlerBase::validateExposed

File

core/modules/search/src/Plugin/views/filter/Search.php, line 101

Class

Search
Filter handler for search keywords.

Namespace

Drupal\search\Plugin\views\filter

Code

public function validateExposed(&$form, FormStateInterface $form_state) {
  if (!isset($this->options['expose']['identifier'])) {
    return;
  }
  $key = $this->options['expose']['identifier'];
  if (!$form_state
    ->isValueEmpty($key)) {
    $this
      ->queryParseSearchExpression($form_state
      ->getValue($key));
    if (count($this->searchQuery
      ->words()) == 0) {
      $form_state
        ->setErrorByName($key, $this
        ->formatPlural(\Drupal::config('search.settings')
        ->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'));
    }
  }
}