function ResourceResponseTestTrait::extractLinks

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

Code

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);
}

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