protected static function IncludeResolver::buildTree in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/IncludeResolver.php \Drupal\jsonapi\IncludeResolver::buildTree()
- 9 core/modules/jsonapi/src/IncludeResolver.php \Drupal\jsonapi\IncludeResolver::buildTree()
Takes an array of exploded paths and builds a tree of field names.
Input example: [ ['one', 'two', 'three'], ['one', 'two', 'four'], ['one', 'two', 'internal'], ]
Output example: [ 'one' => [ 'two' [ 'three' => [], 'four' => [], 'internal' => [], ], ], ]
Parameters
array $paths: An array of exploded include paths.
Return value
array A multi-dimensional array representing a tree of field names to be included. Array keys are the field names. Leaves are empty arrays.
File
- core/modules/ jsonapi/ src/ IncludeResolver.php, line 246 
Class
- IncludeResolver
- Resolves included resources for an entity or collection of entities.
Namespace
Drupal\jsonapiCode
protected static function buildTree(array $paths) {
  $merged = [];
  foreach ($paths as $parts) {
    if (!($field_name = array_shift($parts))) {
      continue;
    }
    $previous = $merged[$field_name] ?? [];
    $merged[$field_name] = array_merge($previous, [
      $parts,
    ]);
  }
  return !empty($merged) ? array_map([
    static::class,
    __FUNCTION__,
  ], $merged) : $merged;
}