function FieldResolver::getFieldItemDefinitions

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

Get all item definitions from a set of resources types by a field name.

Parameters

\Drupal\jsonapi\ResourceType\ResourceType[] $resource_types: The resource types on which the field might exist.

string $field_name: The field for which to retrieve field item definitions.

Return value

\Drupal\Core\TypedData\ComplexDataDefinitionInterface[] The found field item definitions.

1 call to FieldResolver::getFieldItemDefinitions()
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 485

Class

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

Namespace

Drupal\jsonapi\Context

Code

protected function getFieldItemDefinitions(array $resource_types, $field_name) {
    return array_reduce($resource_types, function ($result, ResourceType $resource_type) use ($field_name) {
        
        /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
        $entity_type = $resource_type->getEntityTypeId();
        $bundle = $resource_type->getBundle();
        $definitions = $this->fieldManager
            ->getFieldDefinitions($entity_type, $bundle);
        if (isset($definitions[$field_name])) {
            $result[$resource_type->getTypeName()] = $definitions[$field_name]->getItemDefinition();
        }
        return $result;
    }, []);
}

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