function ResourceResponseTestTrait::getLinkPaths

Same name in other branches
  1. 8.9.x core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::getLinkPaths()
  2. 10 core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::getLinkPaths()
  3. 11.x core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php \Drupal\Tests\jsonapi\Functional\ResourceResponseTestTrait::getLinkPaths()

Turns a list of relationship field names into an array of link paths.

Parameters

array $relationship_field_names: The relationships field names for which to build link paths.

string $type: The type of link to get. Either 'relationship' or 'related'.

Return value

array An array of link paths, keyed by relationship field name.

File

core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php, line 327

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function getLinkPaths(array $relationship_field_names, $type) {
    assert($type === 'relationship' || $type === 'related');
    return array_reduce($relationship_field_names, function ($link_paths, $relationship_field_name) use ($type) {
        $tail = $type === 'relationship' ? 'self' : $type;
        $link_paths[$relationship_field_name] = "data.relationships.{$relationship_field_name}.links.{$tail}.href";
        return $link_paths;
    }, []);
}

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