You are here

function String::op_word in Views (for Drupal 7) 8.3

File

lib/Drupal/views/Plugin/views/filter/String.php, line 273
Definition of Drupal\views\Plugin\views\filter\String.

Class

String
Basic textfield filter to handle string filtering commands including equality, like, not like, etc.

Namespace

Drupal\views\Plugin\views\filter

Code

function op_word($field) {
  $where = $this->operator == 'word' ? db_or() : db_and();

  // Don't filter on empty strings.
  if (empty($this->value)) {
    return;
  }
  preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER);
  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 ? array(
      $words,
    ) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY);
    foreach ($words as $word) {
      $placeholder = $this
        ->placeholder();
      $where
        ->condition($field, '%' . db_like(trim($word, " ,!?")) . '%', 'LIKE');
    }
  }
  if (!$where) {
    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
    ->add_where($this->options['group'], $where);
}