You are here

protected function ResourceTestBase::getRelationshipFieldNames in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getRelationshipFieldNames()
  2. 9 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getRelationshipFieldNames()

Gets a list of public relationship names for the resource type under test.

Parameters

\Drupal\Core\Entity\EntityInterface|null $entity: (optional) The entity for which to get relationship field names.

Return value

array An array of relationship field names.

File

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

Class

ResourceTestBase
Subclass this for every JSON:API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function getRelationshipFieldNames(EntityInterface $entity = NULL) {
  $entity = $entity ?: $this->entity;

  // Only content entity types can have relationships.
  $fields = $entity instanceof ContentEntityInterface ? iterator_to_array($entity) : [];
  return array_reduce($fields, function ($field_names, $field) {

    /** @var \Drupal\Core\Field\FieldItemListInterface $field */
    if (static::isReferenceFieldDefinition($field
      ->getFieldDefinition())) {
      $field_names[] = $this->resourceType
        ->getPublicName($field
        ->getName());
    }
    return $field_names;
  }, []);
}