You are here

public function ResourceEnhancer::enhance in JSON:API Resources 8

File

src/Unstable/Routing/Enhancer/ResourceEnhancer.php, line 47

Class

ResourceEnhancer
Route enhancer for JSON:API Resource routes.

Namespace

Drupal\jsonapi_resources\Unstable\Routing\Enhancer

Code

public function enhance(array $defaults, Request $request) {
  if (!isset($defaults['_jsonapi_resource'])) {
    return $defaults;
  }
  $defaults['_controller'] = 'controller.jsonapi_resource:processRequest';
  if (!isset($defaults['resource_types'])) {
    $resource = $this->classResolver
      ->getInstanceFromDefinition($defaults['_jsonapi_resource']);
    assert($resource instanceof ResourceBase);
    $defaults['resource_types'] = $resource
      ->getRouteResourceTypes($defaults['_route_object'], $defaults['_route']);
  }
  return $defaults;
}