Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/filter/StringFilter.php \Drupal\views\Plugin\views\filter\StringFilter::opContainsWord()
  2. 9 core/modules/views/src/Plugin/views/filter/StringFilter.php \Drupal\views\Plugin\views\filter\StringFilter::opContainsWord()
1 method overrides StringFilter::opContainsWord()
Combine::opContainsWord in core/modules/views/src/Plugin/views/filter/Combine.php
Filters by one or more words.

File

core/modules/views/src/Plugin/views/filter/StringFilter.php, line 365

Class

StringFilter

Namespace

Drupal\views\Plugin\views\filter

Code

protected function opContainsWord($field) {
  $where = $this->operator == 'word' ? $this->query
    ->getConnection()
    ->condition('OR') : $this->query
    ->getConnection()
    ->condition('AND');

  // Don't filter on empty strings.
  if (empty($this->value)) {
    return;
  }
  preg_match_all(static::WORDS_PATTERN, ' ' . $this->value, $matches, PREG_SET_ORDER);
  $operator = $this
    ->getConditionOperator('LIKE');
  foreach ($matches as $match) {
    $phrase = FALSE;

    // Strip off phrase quotes
    if ($match[2][0] == '"') {
      $match[2] = substr($match[2], 1, -1);
      $phrase = TRUE;
    }
    $words = trim($match[2], ',?!();:-');
    $words = $phrase ? [
      $words,
    ] : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
    foreach ($words as $word) {
      $where
        ->condition($field, '%' . $this->connection
        ->escapeLike(trim($word, " ,!?")) . '%', $operator);
    }
  }
  if ($where
    ->count() === 0) {
    return;
  }

  // previously this was a call_user_func_array but that's unnecessary
  // as views will unpack an array that is a single arg.
  $this->query
    ->addWhere($this->options['group'], $where);
}