You are here

public function ResourceBase::getRouteResourceTypes in JSON:API Resources 8

2 methods override ResourceBase::getRouteResourceTypes()
CurrentUserInfo::getRouteResourceTypes in tests/modules/jsonapi_resources_test/src/Resource/CurrentUserInfo.php
FeaturedNodes::getRouteResourceTypes in tests/modules/jsonapi_resources_test/src/Resource/FeaturedNodes.php

File

src/Resource/ResourceBase.php, line 114

Class

ResourceBase
Defines basic functionality for a JSON:API Resource.

Namespace

Drupal\jsonapi_resources\Resource

Code

public function getRouteResourceTypes(Route $route, string $route_name) : array {
  return array_map(function ($resource_type_name) use ($route_name) {
    $resource_type = $this->resourceTypeRepository
      ->getByTypeName($resource_type_name);
    if (is_null($resource_type)) {

      // @todo: try to move this exception into Drupal\jsonapi_resources\Routing\ResourceRoutes::ensureResourceImplementationValid().
      throw new RouteDefinitionException("The {$route_name} route definition's _jsonapi_resource_types route default declares the resource type {$resource_type_name} but a resource type by that name does not exist.");
    }
    return $resource_type;
  }, $route
    ->getDefault('_jsonapi_resource_types') ?: []);
}