function IncludeResolver::resolve

Same name in other branches
  1. 9 core/modules/jsonapi/src/IncludeResolver.php \Drupal\jsonapi\IncludeResolver::resolve()
  2. 8.9.x core/modules/jsonapi/src/IncludeResolver.php \Drupal\jsonapi\IncludeResolver::resolve()
  3. 11.x 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 71

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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.