You are here

public function EntityAccessDeniedHttpException::__construct in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Exception/EntityAccessDeniedHttpException.php \Drupal\jsonapi\Exception\EntityAccessDeniedHttpException::__construct()

EntityAccessDeniedHttpException constructor.

Parameters

\Drupal\Core\Entity\EntityInterface|null $entity: The entity, or NULL when an entity is being created.

\Drupal\Core\Access\AccessResultInterface $entity_access: The access result.

string $pointer: (optional) The pointer.

string $messsage: (Optional) The display to display.

\Exception|null $previous: The previous exception.

array $headers: The headers.

int $code: The code.

File

src/Exception/EntityAccessDeniedHttpException.php, line 51

Class

EntityAccessDeniedHttpException
Enhances the access denied exception with information about the entity.

Namespace

Drupal\jsonapi\Exception

Code

public function __construct($entity, AccessResultInterface $entity_access, $pointer, $messsage = 'The current user is not allowed to GET the selected resource.', \Exception $previous = NULL, array $headers = [], $code = 0) {
  assert(is_null($entity) || $entity instanceof EntityInterface);
  parent::__construct(403, $messsage, $previous, $headers, $code);
  $error = [
    'entity' => $entity,
    'pointer' => $pointer,
    'reason' => NULL,
  ];
  if ($entity_access instanceof AccessResultReasonInterface) {
    $error['reason'] = $entity_access
      ->getReason();
  }
  $this->error = $error;
}