protected static function ResourceResponseTestTrait::extractLinks in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::extractLinks()
- 9 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::extractLinks()
Extracts links from a document using a list of relationship field names.
Parameters
array $link_paths: A list of paths to link values keyed by a name.
array $document: A JSON:API document.
Return value
array The extracted links, keyed by the original associated key name.
File
- core/
modules/ jsonapi/ tests/ src/ Functional/ ResourceResponseTestTrait.php, line 347
Class
- ResourceResponseTestTrait
- Utility methods for handling resource responses.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
protected static function extractLinks(array $link_paths, array $document) {
return array_map(function ($link_path) use ($document) {
$link = array_reduce(explode('.', $link_path), 'array_column', [
$document,
]);
return $link ? reset($link) : NULL;
}, $link_paths);
}