You are here

protected static function EntityResource::toTargets in JSON:API 8

Maps a list of entity reference field objects to a list of targets.

Parameters

\Drupal\Core\Field\EntityReferenceFieldItemListInterface $relationship_list: A list of entity reference field objects.

Return value

string[]|int[] A list of targets.

1 call to EntityResource::toTargets()
EntityResource::relationshipArityIsAffected in src/Controller/EntityResource.php
Checks whether relationship arity is affected.

File

src/Controller/EntityResource.php, line 653

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected static function toTargets(EntityReferenceFieldItemListInterface $relationship_list) {
  $main_property_name = $relationship_list
    ->getFieldDefinition()
    ->getFieldStorageDefinition()
    ->getMainPropertyName();
  $values = [];
  foreach ($relationship_list
    ->getIterator() as $relationship) {
    $values[] = $relationship
      ->getValue()[$main_property_name];
  }
  return $values;
}