You are here

protected static function ResourceIdentifier::getDataReferencePropertyName in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::getDataReferencePropertyName()

Helper method to determine which field item property contains an entity.

Parameters

\Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $item: The entity reference item for which to determine the entity property name.

Return value

string The property name which has an entity as its value.

2 calls to ResourceIdentifier::getDataReferencePropertyName()
ResourceIdentifier::getVirtualOrMissingResourceIdentifier in core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php
Creates a ResourceIdentifier for a NULL or FALSE entity reference item.
ResourceIdentifier::toResourceIdentifier in core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php
Creates a ResourceIdentifier object.

File

core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php, line 394

Class

ResourceIdentifier
Represents a JSON:API resource identifier object.

Namespace

Drupal\jsonapi\JsonApiResource

Code

protected static function getDataReferencePropertyName(EntityReferenceItem $item) {
  foreach ($item
    ->getDataDefinition()
    ->getPropertyDefinitions() as $property_name => $property_definition) {
    if ($property_definition instanceof DataReferenceDefinitionInterface) {
      return $property_name;
    }
  }
}