function FieldResolver::getDataReferencePropertyName

Same name and namespace in other branches
  1. 8.9.x core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getDataReferencePropertyName()
  2. 10 core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getDataReferencePropertyName()
  3. 11.x core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getDataReferencePropertyName()

Determines the reference property name for the remaining unresolved parts.

Parameters

\Drupal\Core\TypedData\ComplexDataDefinitionInterface[] $candidate_definitions: A list of targeted field item definitions specified by the path.

string[] $remaining_parts: The remaining path parts.

string[] $unresolved_path_parts: The unresolved path parts.

Return value

string The reference name.

1 call to FieldResolver::getDataReferencePropertyName()
FieldResolver::resolveInternalEntityQueryPath in core/modules/jsonapi/src/Context/FieldResolver.php
Resolves external field expressions into entity query compatible paths.

File

core/modules/jsonapi/src/Context/FieldResolver.php, line 647

Class

FieldResolver
A service that evaluates external path expressions against Drupal fields.

Namespace

Drupal\jsonapi\Context

Code

protected static function getDataReferencePropertyName(array $candidate_definitions, array $remaining_parts, array $unresolved_path_parts) {
    $unique_reference_names = static::getAllDataReferencePropertyNames($candidate_definitions);
    if (count($unique_reference_names) > 1) {
        $choices = array_map(function ($reference_name) use ($unresolved_path_parts, $remaining_parts) {
            $prior_parts = array_slice($unresolved_path_parts, 0, count($unresolved_path_parts) - count($remaining_parts));
            return implode('.', array_merge($prior_parts, [
                $reference_name,
            ], $remaining_parts));
        }, $unique_reference_names);
        // @todo Add test coverage for this in https://www.drupal.org/project/drupal/issues/2971281
        $message = sprintf('Ambiguous path. Try one of the following: %s, in place of the given path: %s', implode(', ', $choices), implode('.', $unresolved_path_parts));
        $cacheability = (new CacheableMetadata())->addCacheContexts([
            'url.query_args:filter',
            'url.query_args:sort',
        ]);
        throw new CacheableBadRequestHttpException($cacheability, $message);
    }
    return $unique_reference_names[0];
}

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