You are here

protected static function ResourceResponseTestTrait::getLinkPaths in Drupal 9

Same name and namespace in other branches
  1. 8 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;
  }, []);
}