You are here

protected static function FieldResolver::getAllDataReferencePropertyNames in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getAllDataReferencePropertyNames()
  2. 9 core/modules/jsonapi/src/Context/FieldResolver.php \Drupal\jsonapi\Context\FieldResolver::getAllDataReferencePropertyNames()

Gets all unique reference property names from the given field definitions.

Parameters

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

Return value

string[] The reference property names, if any.

File

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

Class

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

Namespace

Drupal\jsonapi\Context

Code

protected static function getAllDataReferencePropertyNames(array $candidate_definitions) {
  $reference_property_names = array_reduce($candidate_definitions, function (array $reference_property_names, ComplexDataDefinitionInterface $definition) {
    $property_definitions = $definition
      ->getPropertyDefinitions();
    foreach ($property_definitions as $property_name => $property_definition) {
      if ($property_definition instanceof DataReferenceDefinitionInterface) {
        $target_definition = $property_definition
          ->getTargetDefinition();
        assert($target_definition instanceof EntityDataDefinitionInterface, 'Entity reference fields should only be able to reference entities.');
        $reference_property_names[] = $property_name . ':' . $target_definition
          ->getEntityTypeId();
      }
    }
    return $reference_property_names;
  }, []);
  return array_unique($reference_property_names);
}