protected function ResourceTestBase::getNestedIncludePaths in Drupal 9
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getNestedIncludePaths()
Gets an array of all nested include paths to be tested.
Parameters
int $depth: (optional) The maximum depth to which included paths should be nested.
Return value
array An array of nested include paths.
1 call to ResourceTestBase::getNestedIncludePaths()
- ResourceTestBase::doTestIncluded in core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php - Tests included resources.
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceTestBase.php, line 3426
Class
- ResourceTestBase
- Subclass this for every JSON:API resource type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected function getNestedIncludePaths($depth = 3) {
$get_nested_relationship_field_names = function (EntityInterface $entity, $depth, $path = "") use (&$get_nested_relationship_field_names) {
$relationship_field_names = $this
->getRelationshipFieldNames($entity);
if ($depth > 0) {
$paths = [];
foreach ($relationship_field_names as $field_name) {
$next = $path ? "{$path}.{$field_name}" : $field_name;
$internal_field_name = $this->resourceType
->getInternalName($field_name);
if ($target_entity = $entity->{$internal_field_name}->entity) {
$deep = $get_nested_relationship_field_names($target_entity, $depth - 1, $next);
$paths = array_merge($paths, $deep);
}
else {
$paths[] = $next;
}
}
return $paths;
}
return array_map(function ($target_name) use ($path) {
return "{$path}.{$target_name}";
}, $relationship_field_names);
};
return $get_nested_relationship_field_names($this->entity, $depth);
}