protected function ResourceTestBase::getRelationshipFieldNames in JSON:API 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getRelationshipFieldNames()
Gets a list of relationship field 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 tests/
src/ Functional/ ResourceTestBase.php - Tests included resources.
- ResourceTestBase::doTestRelated in tests/
src/ Functional/ ResourceTestBase.php - Performs one round of related route testing.
- ResourceTestBase::doTestRelationshipGet in tests/
src/ Functional/ ResourceTestBase.php - Performs one round of relationship route testing.
- ResourceTestBase::getNestedIncludePaths in tests/
src/ Functional/ ResourceTestBase.php - Gets an array of of all nested include paths to be tested.
- ResourceTestBase::testCollection in tests/
src/ Functional/ ResourceTestBase.php - Tests GETting a collection of resources.
File
- tests/
src/ Functional/ ResourceTestBase.php, line 2729
Class
- ResourceTestBase
- Subclass this for every JSON API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
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[] = $field
->getName();
}
return $field_names;
}, []);
}