You are here

protected function RequestHandler::action in JSON:API 8

Gets the method to execute in the entity resource.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request being handled.

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The JSON API resource type for the current request.

Return value

string The method to execute in the EntityResource.

1 call to RequestHandler::action()
RequestHandler::handle in src/Controller/RequestHandler.php
Handles a JSON API request.

File

src/Controller/RequestHandler.php, line 213

Class

RequestHandler
Acts as request forwarder for \Drupal\jsonapi\Controller\EntityResource.

Namespace

Drupal\jsonapi\Controller

Code

protected function action(Request $request, ResourceType $resource_type) {
  $on_relationship = (bool) $request
    ->get('_on_relationship');
  switch (strtolower($request
    ->getMethod())) {
    case 'head':
    case 'get':
      if ($on_relationship) {
        return 'getRelationship';
      }
      elseif ($request
        ->get('related')) {
        return 'getRelated';
      }
      return $request
        ->get($resource_type
        ->getEntityTypeId()) ? 'getIndividual' : 'getCollection';
    case 'post':
      return $on_relationship ? 'createRelationship' : 'createIndividual';
    case 'patch':
      return $on_relationship ? 'patchRelationship' : 'patchIndividual';
    case 'delete':
      return $on_relationship ? 'deleteRelationship' : 'deleteIndividual';
  }
}