protected function Filter::buildGroup in JSON:API 8
Same name and namespace in other branches
- 8.2 src/Query/Filter.php \Drupal\jsonapi\Query\Filter::buildGroup()
Applies the root condition to the given query.
Parameters
\Drupal\Entity\Query\QueryInterface $query: The query to which the filter should be applied.
\Drupal\Entity\Query\EntityConditionGroup $condition_group: The condition group to build.
Return value
\Drupal\Entity\Query\QueryInterface The query with the filter applied.
1 call to Filter::buildGroup()
- Filter::queryCondition in src/
Query/ Filter.php - Applies the root condition to the given query.
File
- src/
Query/ Filter.php, line 70
Class
- Filter
- Gathers information about the filter parameter.
Namespace
Drupal\jsonapi\QueryCode
protected function buildGroup(QueryInterface $query, EntityConditionGroup $condition_group) {
// Create a condition group using the original query.
switch ($condition_group
->conjunction()) {
case 'AND':
$group = $query
->andConditionGroup();
break;
case 'OR':
$group = $query
->orConditionGroup();
break;
}
// 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;
}