You are here

protected function SearchApiFilterTrait::opHelper in Search API 8

Adds a filter to the search query.

Overridden to avoid errors because of SQL-specific functionality being used when "Many To One" is used as a base class.

See also

\Drupal\views\Plugin\views\filter\ManyToOne::opHelper()

File

src/Plugin/views/filter/SearchApiFilterTrait.php, line 44

Class

SearchApiFilterTrait
Provides a trait to use for Search API Views filters.

Namespace

Drupal\search_api\Plugin\views\filter

Code

protected function opHelper() {

  // Form API returns unchecked options in the form of option_id => 0. This
  // breaks the generated query for "is all of" filters so we remove them.
  $this->value = array_filter($this->value, 'static::arrayFilterZero');
  if (empty($this->value)) {
    return;
  }
  if ($this->operator !== 'and') {
    $operator = $this->operator === 'not' ? 'NOT IN' : 'IN';
    $this
      ->getQuery()
      ->addCondition($this->realField, $this->value, $operator, $this->options['group']);
    return;
  }
  $condition_group = $this
    ->getQuery()
    ->createConditionGroup();
  foreach ($this->value as $value) {
    $condition_group
      ->addCondition($this->realField, $value, '=');
  }
  $this
    ->getQuery()
    ->addConditionGroup($condition_group, $this->options['group']);
}