function Filter::buildGroup

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/src/Query/Filter.php \Drupal\jsonapi\Query\Filter::buildGroup()
  2. 8.9.x core/modules/jsonapi/src/Query/Filter.php \Drupal\jsonapi\Query\Filter::buildGroup()
  3. 10 core/modules/jsonapi/src/Query/Filter.php \Drupal\jsonapi\Query\Filter::buildGroup()

Applies the root condition to the given query.

Parameters

\Drupal\Core\Entity\Query\QueryInterface $query: The query to which the filter should be applied.

\Drupal\jsonapi\Query\EntityConditionGroup $condition_group: The condition group to build.

Return value

\Drupal\Core\Entity\Query\ConditionInterface The query with the filter applied.

1 call to Filter::buildGroup()
Filter::queryCondition in core/modules/jsonapi/src/Query/Filter.php
Applies the root condition to the given query.

File

core/modules/jsonapi/src/Query/Filter.php, line 102

Class

Filter
Gathers information about the filter parameter.

Namespace

Drupal\jsonapi\Query

Code

protected function buildGroup(QueryInterface $query, EntityConditionGroup $condition_group) {
    // Create a condition group using the original query.
    $group = match ($condition_group->conjunction()) {    'AND' => $query->andConditionGroup(),
        'OR' => $query->orConditionGroup(),
    
    };
    // Get all children of the group.
    $members = $condition_group->members();
    foreach ($members as $member) {
        // If the child is simply a condition, add it to the new group.
        if ($member instanceof EntityCondition) {
            if ($member->operator() == 'IS NULL') {
                $group->notExists($member->field());
            }
            elseif ($member->operator() == 'IS NOT NULL') {
                $group->exists($member->field());
            }
            else {
                $group->condition($member->field(), $member->value(), $member->operator());
            }
        }
        elseif ($member instanceof EntityConditionGroup) {
            // Add the subgroup to this new group.
            $subgroup = $this->buildGroup($query, $member);
            $group->condition($subgroup);
        }
    }
    // Return the constructed group so that it can be added to the query.
    return $group;
}

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