You are here

protected function FieldResolver::getFieldItemDefinitions in JSON:API 8.2

Same name and namespace in other branches
  1. 8 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 src/Context/FieldResolver.php
Resolves external field expressions into entity query compatible paths.

File

src/Context/FieldResolver.php, line 468

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;
  }, []);
}