You are here

public function IncludeResolver::resolve in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/IncludeResolver.php \Drupal\jsonapi\IncludeResolver::resolve()

Resolves included resources.

Parameters

\Drupal\jsonapi\JsonApiResource\ResourceIdentifierInterface|\Drupal\jsonapi\JsonApiResource\ResourceObjectData $data: The resource(s) for which to resolve includes.

string $include_parameter: The include query parameter to resolve.

Return value

\Drupal\jsonapi\JsonApiResource\IncludedData An IncludedData object of resolved resources to be included.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if an included entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if a storage handler couldn't be loaded.

File

core/modules/jsonapi/src/IncludeResolver.php, line 70

Class

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

Namespace

Drupal\jsonapi

Code

public function resolve($data, $include_parameter) {
  assert($data instanceof ResourceObject || $data instanceof ResourceObjectData);
  $data = $data instanceof ResourceObjectData ? $data : new ResourceObjectData([
    $data,
  ], 1);
  $include_tree = static::toIncludeTree($data, $include_parameter);
  return IncludedData::deduplicate($this
    ->resolveIncludeTree($include_tree, $data));
}