function ResourceResponseSubscriberTest::generateRouteRequirements

Same name and namespace in other branches
  1. 9 core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php \Drupal\Tests\rest\Unit\EventSubscriber\ResourceResponseSubscriberTest::generateRouteRequirements()
  2. 8.9.x core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php \Drupal\Tests\rest\Unit\EventSubscriber\ResourceResponseSubscriberTest::generateRouteRequirements()
  3. 10 core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php \Drupal\Tests\rest\Unit\EventSubscriber\ResourceResponseSubscriberTest::generateRouteRequirements()

Generates route requirements based on supported formats.

Parameters

array $supported_response_formats: The supported response formats to add to the route requirements.

array $supported_request_formats: The supported request formats to add to the route requirements.

Return value

array An array of route requirements.

3 calls to ResourceResponseSubscriberTest::generateRouteRequirements()
ResourceResponseSubscriberTest::testOnResponseWithCacheableResponse in core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php
@covers ::onResponse @covers ::getResponseFormat @covers ::renderResponseBody @covers ::flattenResponse
ResourceResponseSubscriberTest::testOnResponseWithUncacheableResponse in core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php
@covers ::onResponse @covers ::getResponseFormat @covers ::renderResponseBody @covers ::flattenResponse
ResourceResponseSubscriberTest::testResponseFormat in core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php
Tests the response format.

File

core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php, line 414

Class

ResourceResponseSubscriberTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21rest%21src%21EventSubscriber%21ResourceResponseSubscriber.php/class/ResourceResponseSubscriber/11.x" title="Response subscriber that serializes and removes ResourceResponses&#039; data." class="local">\Drupal\rest\EventSubscriber\ResourceResponseSubscriber</a> @group rest

Namespace

Drupal\Tests\rest\Unit\EventSubscriber

Code

protected function generateRouteRequirements(array $supported_response_formats, array $supported_request_formats) {
    $route_requirements = [
        '_format' => implode('|', $supported_response_formats),
    ];
    if (!empty($supported_request_formats)) {
        $route_requirements['_content_type_format'] = implode('|', $supported_request_formats);
    }
    return $route_requirements;
}

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