protected function EntityResource::getEntityFromResourceIdentifier in JSON:API 8.2
Loads the entity targeted by a resource identifier.
Parameters
\Drupal\jsonapi\JsonApiResource\ResourceIdentifier $resource_identifier: A resource identifier.
Return value
\Drupal\Core\Entity\EntityInterface The entity targeted by a resource identifier.
Throws
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException Thrown if the given resource identifier targets a resource type or resource which does not exist.
File
- src/
Controller/ EntityResource.php, line 925
Class
- EntityResource
- Process all entity requests.
Namespace
Drupal\jsonapi\ControllerCode
protected function getEntityFromResourceIdentifier(ResourceIdentifier $resource_identifier) {
$resource_type_name = $resource_identifier
->getTypeName();
if (!($target_resource_type = $this->resourceTypeRepository
->getByTypeName($resource_type_name))) {
throw new BadRequestHttpException("The resource type `{$resource_type_name}` does not exist.");
}
$id = $resource_identifier
->getId();
if (!($targeted_resource = $this->entityRepository
->loadEntityByUuid($target_resource_type
->getEntityTypeId(), $id))) {
throw new BadRequestHttpException("The targeted `{$resource_type_name}` resource with ID `{$id}` does not exist.");
}
return $targeted_resource;
}