You are here

protected static function IncludeResolver::toIncludeTree in JSON:API 8.2

Returns a tree of field names to include from an include parameter.

Parameters

\Drupal\jsonapi\JsonApiResource\ResourceObjectData $data: The base resources for which includes should be resolved.

string $include_parameter: The raw include parameter value.

Return value

array An multi-dimensional array representing a tree of field names to be included. Array keys are the field names. Leaves are empty arrays.

1 call to IncludeResolver::toIncludeTree()
IncludeResolver::resolve in src/IncludeResolver.php
Resolves included resources.

File

src/IncludeResolver.php, line 172

Class

IncludeResolver
Resolves included resources for an entity or collection of entities.

Namespace

Drupal\jsonapi

Code

protected static function toIncludeTree(ResourceObjectData $data, $include_parameter) {

  // $include_parameter: 'one.two.three, one.two.four'.
  $include_paths = array_map('trim', explode(',', $include_parameter));

  // $exploded_paths: [['one', 'two', 'three'], ['one', 'two', 'four']].
  $exploded_paths = array_map(function ($include_path) {
    return array_map('trim', explode('.', $include_path));
  }, $include_paths);
  $resolved_paths = [];

  /* @var \Drupal\jsonapi\JsonApiResource\ResourceIdentifierInterface $resource_object */
  foreach ($data as $resource_object) {
    $resolved_paths = array_merge($resolved_paths, static::resolveInternalIncludePaths($resource_object
      ->getResourceType(), $exploded_paths));
  }
  return static::buildTree($resolved_paths);
}