You are here

protected function FilterNormalizer::buildTree in JSON: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 FilterNormalizer::buildTree()
FilterNormalizer::denormalizeItems in src/Normalizer/FilterNormalizer.php
Denormalizes the given filter items into a single EntityConditionGroup.

File

src/Normalizer/FilterNormalizer.php, line 226

Class

FilterNormalizer
The normalizer used for JSON API filters.

Namespace

Drupal\jsonapi\Normalizer

Code

protected 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, $this
          ->buildTree($item, $items));
      }
      elseif (isset($item[static::CONDITION_KEY])) {
        $condition = $this->conditionDenormalizer
          ->denormalize($item[static::CONDITION_KEY], EntityCondition::class);
        array_push($members, $condition);
      }
    }
  }
  $root[static::GROUP_KEY]['members'] = $members;

  // Denormalize the root into a condition group.
  return $this->groupDenormalizer
    ->denormalize($root[static::GROUP_KEY], EntityConditionGroup::class);
}