protected function Filter::buildGroup in JSON:API Search API 8
Applies the root condition to the given query.
Parameters
\Drupal\search_api\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\search_api\Query\ConditionGroupInterface 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 100
Class
- Filter
- Gathers information about the filter parameter.
Namespace
Drupal\jsonapi_search_api\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
->createConditionGroup();
break;
case 'OR':
$group = $query
->createConditionGroup('OR');
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
->addCondition($member
->field(), NULL, '=');
}
elseif ($member
->operator() == 'IS NOT NULL') {
$group
->addCondition($member
->field(), NULL, '<>');
}
else {
$group
->addCondition($member
->field(), $member
->value(), $member
->operator());
}
}
elseif ($member instanceof EntityConditionGroup) {
// Add the subgroup to this new group.
$subgroup = $this
->buildGroup($query, $member);
$group
->addConditionGroup($subgroup);
}
}
// Return the constructed group so that it can be added to the query.
return $group;
}