public function EntityAccessDeniedHttpException::__construct in Drupal 10
Same name and namespace in other branches
- 8 core/modules/jsonapi/src/Exception/EntityAccessDeniedHttpException.php \Drupal\jsonapi\Exception\EntityAccessDeniedHttpException::__construct()
- 9 core/modules/jsonapi/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 $message: (Optional) The display to display.
string $relationship_field: (Optional) A relationship field name if access was denied because the user does not have permission to view an entity's relationship field.
\Exception|null $previous: The previous exception.
int $code: The code.
Overrides CacheableAccessDeniedHttpException::__construct
File
- core/
modules/ jsonapi/ src/ Exception/ EntityAccessDeniedHttpException.php, line 61
Class
- EntityAccessDeniedHttpException
- Enhances the access denied exception with information about the entity.
Namespace
Drupal\jsonapi\ExceptionCode
public function __construct($entity, AccessResultInterface $entity_access, $pointer, $message = 'The current user is not allowed to GET the selected resource.', $relationship_field = NULL, \Exception $previous = NULL, $code = 0) {
assert(is_null($entity) || $entity instanceof EntityInterface);
parent::__construct(CacheableMetadata::createFromObject($entity_access), $message, $previous, $code);
$error = [
'entity' => $entity,
'pointer' => $pointer,
'reason' => NULL,
'relationship_field' => $relationship_field,
];
if ($entity_access instanceof AccessResultReasonInterface) {
$error['reason'] = $entity_access
->getReason();
}
$this->error = $error;
// @todo: remove this ternary operation in https://www.drupal.org/project/drupal/issues/2997594.
$this->resourceIdentifier = $entity ? ResourceIdentifier::fromEntity($entity) : NULL;
}