Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityAccessDeniedHttpException.php

function 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\Exception

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal