function Routes::routes

Same name in other branches
  1. 9 core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::routes()
  2. 8.9.x core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::routes()
  3. 10 core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::routes()
1 string reference to 'Routes::routes'
jsonapi.routing.yml in core/modules/jsonapi/jsonapi.routing.yml
core/modules/jsonapi/jsonapi.routing.yml

File

core/modules/jsonapi/src/Routing/Routes.php, line 110

Class

Routes
Defines dynamic routes.

Namespace

Drupal\jsonapi\Routing

Code

public function routes() {
    $routes = new RouteCollection();
    $upload_routes = new RouteCollection();
    // JSON:API's routes: entry point + routes for every resource type.
    foreach ($this->resourceTypeRepository
        ->all() as $resource_type) {
        $routes->addCollection(static::getRoutesForResourceType($resource_type, $this->jsonApiBasePath));
        $upload_routes->addCollection(static::getFileUploadRoutesForResourceType($resource_type, $this->jsonApiBasePath));
    }
    $routes->add('jsonapi.resource_list', static::getEntryPointRoute($this->jsonApiBasePath));
    // Require the JSON:API media type header on every route, except on file
    // upload routes, where we require `application/octet-stream`.
    $routes->addRequirements([
        '_content_type_format' => 'api_json',
    ]);
    $upload_routes->addRequirements([
        '_content_type_format' => 'bin',
    ]);
    $routes->addCollection($upload_routes);
    // Enable all available authentication providers.
    $routes->addOptions([
        '_auth' => $this->providerIds,
    ]);
    // Flag every route as belonging to the JSON:API module.
    $routes->addDefaults([
        static::JSON_API_ROUTE_FLAG_KEY => TRUE,
    ]);
    // All routes serve only the JSON:API media type.
    $routes->addRequirements([
        '_format' => 'api_json',
    ]);
    return $routes;
}

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