function ResourceTestBase::getRelationshipFieldNames

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getRelationshipFieldNames()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getRelationshipFieldNames()
  3. 11.x 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.

5 calls to ResourceTestBase::getRelationshipFieldNames()
ResourceTestBase::doTestIncluded in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests included resources.
ResourceTestBase::doTestRelated in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Performs one round of related route testing.
ResourceTestBase::doTestRelationshipGet in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Performs one round of relationship route testing.
ResourceTestBase::getNestedIncludePaths in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Gets an array of all nested include paths to be tested.
ResourceTestBase::testCollection in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests GETting a collection of resources.

File

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

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;
    }, []);
}

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