function ResourceTestBase::isReferenceFieldDefinition

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::isReferenceFieldDefinition()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::isReferenceFieldDefinition()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::isReferenceFieldDefinition()

Determines if a given field definition is a reference field.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition to inspect.

Return value

bool TRUE if the field definition is found to be a reference field. FALSE otherwise.

1 call to ResourceTestBase::isReferenceFieldDefinition()
ResourceTestBase::getRelationshipFieldNames in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Gets a list of public relationship names for the resource type under test.

File

core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php, line 3458

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function isReferenceFieldDefinition(FieldDefinitionInterface $field_definition) {
    
    /** @var \Drupal\Core\Field\TypedData\FieldItemDataDefinition $item_definition */
    $item_definition = $field_definition->getItemDefinition();
    $main_property = $item_definition->getMainPropertyName();
    $property_definition = $item_definition->getPropertyDefinition($main_property);
    return $property_definition instanceof DataReferenceTargetDefinition;
}

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