function BooleanOperator::queryOpBoolean

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::queryOpBoolean()
  2. 8.9.x core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::queryOpBoolean()
  3. 10 core/modules/views/src/Plugin/views/filter/BooleanOperator.php \Drupal\views\Plugin\views\filter\BooleanOperator::queryOpBoolean()

Adds a where condition to the query for a boolean value.

Parameters

string $field: The field name to add the where condition for.

string $query_operator: (optional) Either self::EQUAL or self::NOT_EQUAL. Defaults to self::EQUAL.

1 call to BooleanOperator::queryOpBoolean()
FilterBooleanOperatorDefaultTest::query in core/modules/views/tests/modules/views_test_data/src/Plugin/views/filter/FilterBooleanOperatorDefaultTest.php
Add this filter to the query.

File

core/modules/views/src/Plugin/views/filter/BooleanOperator.php, line 253

Class

BooleanOperator
Simple filter to handle matching of boolean values.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function queryOpBoolean($field, $query_operator = self::EQUAL) {
    if (empty($this->value)) {
        if ($this->accept_null) {
            if ($query_operator === self::EQUAL) {
                $condition = $this->query
                    ->getConnection()
                    ->condition('OR')
                    ->condition($field, 0, $query_operator)
                    ->isNull($field);
            }
            else {
                $condition = $this->query
                    ->getConnection()
                    ->condition('AND')
                    ->condition($field, 0, $query_operator)
                    ->isNotNull($field);
            }
            $this->query
                ->addWhere($this->options['group'], $condition);
        }
        else {
            $this->query
                ->addWhere($this->options['group'], $field, 0, $query_operator);
        }
    }
    else {
        if (!empty($this->definition['use_equal'])) {
            // Forces a self::EQUAL operator instead of a self::NOT_EQUAL for
            // performance reasons.
            if ($query_operator === self::EQUAL) {
                $this->query
                    ->addWhere($this->options['group'], $field, 1, self::EQUAL);
            }
            else {
                $this->query
                    ->addWhere($this->options['group'], $field, 0, self::EQUAL);
            }
        }
        else {
            $this->query
                ->addWhere($this->options['group'], $field, 1, $query_operator);
        }
    }
}

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