protected static function Filter::buildTree in JSON:API Search API 8
Organizes the flat, normalized filter items into a tree structure.
Parameters
array $root: The root of the tree to build.
array $items: The normalized entity conditions and groups.
Return value
\Drupal\jsonapi\Query\EntityConditionGroup The entity condition group
1 call to Filter::buildTree()
- Filter::buildEntityConditionGroup in src/
Query/ Filter.php - Denormalizes the given filter items into a single EntityConditionGroup.
File
- src/
Query/ Filter.php, line 267
Class
- Filter
- Gathers information about the filter parameter.
Namespace
Drupal\jsonapi_search_api\QueryCode
protected static function buildTree(array $root, array $items) {
$id = $root['id'];
// Recursively build a tree of denormalized conditions and condition groups.
$members = [];
foreach ($items as $item) {
if ($item[static::MEMBER_KEY] == $id) {
if (isset($item[static::GROUP_KEY])) {
array_push($members, static::buildTree($item, $items));
}
elseif (isset($item[static::CONDITION_KEY])) {
$condition = EntityCondition::createFromQueryParameter($item[static::CONDITION_KEY]);
array_push($members, $condition);
}
}
}
$root[static::GROUP_KEY]['members'] = $members;
// Denormalize the root into a condition group.
return new EntityConditionGroup($root[static::GROUP_KEY]['conjunction'], $root[static::GROUP_KEY]['members']);
}