function ResourceResponseTestTrait::errorsToOmittedObject

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

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