EntityAccessDeniedHttpExceptionNormalizer.php in JSON:API 8
File
src/Normalizer/EntityAccessDeniedHttpExceptionNormalizer.php
View source
<?php
namespace Drupal\jsonapi\Normalizer;
use Drupal\jsonapi\Exception\EntityAccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\HttpException;
class EntityAccessDeniedHttpExceptionNormalizer extends HttpExceptionNormalizer {
protected $supportedInterfaceOrClass = EntityAccessDeniedHttpException::class;
protected function buildErrorObjects(HttpException $exception) {
$errors = parent::buildErrorObjects($exception);
if ($exception instanceof EntityAccessDeniedHttpException) {
$error = $exception
->getError();
$entity = $error['entity'];
$pointer = $error['pointer'];
$reason = $error['reason'];
if (isset($entity)) {
$errors[0]['id'] = sprintf('/%s--%s/%s', $entity
->getEntityTypeId(), $entity
->bundle(), $entity
->uuid());
}
$errors[0]['source']['pointer'] = $pointer;
if ($reason) {
$errors[0]['detail'] = isset($errors[0]['detail']) ? $errors[0]['detail'] . ' ' . $reason : $reason;
}
}
return $errors;
}
}