function ResourceIdentifier::getDataReferencePropertyName

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::getDataReferencePropertyName()
  2. 10 core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php \Drupal\jsonapi\JsonApiResource\ResourceIdentifier::getDataReferencePropertyName()
  3. 11.x 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 396

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;
        }
    }
}

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