You are here

protected static function ResourceResponseTestTrait::errorsToOmittedObject 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::errorsToOmittedObject()

Maps error objects into an omitted object.

Parameters

array $errors: An array of error objects.

Return value

array A new omitted object.

3 calls to ResourceResponseTestTrait::errorsToOmittedObject()
ResourceResponseTestTrait::toCollectionResourceResponse in core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
Merges individual responses into a collection response.
ResourceTestBase::decorateExpectedResponseForIncludedFields in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Decorates the expected response with included data and cache metadata.
ResourceTestBase::testRevisions in core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
Tests individual and collection revisions.

File

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

Class

ResourceResponseTestTrait
Utility methods for handling resource responses.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected static function errorsToOmittedObject(array $errors) {
  $omitted = [
    'detail' => 'Some resources have been omitted because of insufficient authorization.',
    'links' => [
      'help' => [
        'href' => 'https://www.drupal.org/docs/8/modules/json-api/filtering#filters-access-control',
      ],
    ],
  ];
  foreach ($errors as $error) {
    $omitted['links']['item--' . substr(Crypt::hashBase64($error['links']['via']['href']), 0, 7)] = [
      'href' => $error['links']['via']['href'],
      'meta' => [
        'detail' => $error['detail'],
        'rel' => 'item',
      ],
    ];
  }
  return $omitted;
}