You are here

public function EntityResource::getIndividual in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getIndividual()

Gets the individual entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The loaded entity.

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\Drupal\jsonapi\ResourceResponse The response.

Throws

\Drupal\jsonapi\Exception\EntityAccessDeniedHttpException Thrown when access to the entity is not allowed.

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 206

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

public function getIndividual(EntityInterface $entity, Request $request) {
  $resource_object = $this->entityAccessChecker
    ->getAccessCheckedResourceObject($entity);
  if ($resource_object instanceof EntityAccessDeniedHttpException) {
    throw $resource_object;
  }
  $primary_data = new ResourceObjectData([
    $resource_object,
  ], 1);
  $response = $this
    ->buildWrappedResponse($primary_data, $request, $this
    ->getIncludes($request, $primary_data));
  return $response;
}