public function RequestHandler::handle in JSON:API 8
Handles a JSON API request.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The HTTP request object.
\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON API resource type for the current request.
Return value
\Drupal\Core\Cache\CacheableResponseInterface The response object.
File
- src/Controller/ RequestHandler.php, line 114 
Class
- RequestHandler
- Acts as request forwarder for \Drupal\jsonapi\Controller\EntityResource.
Namespace
Drupal\jsonapi\ControllerCode
public function handle(Request $request, ResourceType $resource_type) {
  $unserialized = $this
    ->deserialize($request, $resource_type);
  // Determine the request parameters that should be passed to the resource
  // plugin.
  $parameters = [];
  $entity_type_id = $resource_type
    ->getEntityTypeId();
  if ($entity = $request
    ->get($entity_type_id)) {
    $parameters[$entity_type_id] = $entity;
  }
  if ($related = $request
    ->get('related')) {
    $parameters['related'] = $related;
  }
  // Invoke the operation on the resource plugin.
  $action = $this
    ->action($request, $resource_type);
  $resource = $this
    ->resourceFactory($resource_type);
  // Only add the unserialized data if there is something there.
  $extra_parameters = $unserialized ? [
    $unserialized,
    $request,
  ] : [
    $request,
  ];
  return call_user_func_array([
    $resource,
    $action,
  ], array_merge($parameters, $extra_parameters));
}