You are here

class EntityAccessDeniedHttpExceptionNormalizer in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Normalizer/EntityAccessDeniedHttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer

Normalizes an EntityAccessDeniedException.

Normalizes an EntityAccessDeniedException in compliance with the JSON API specification. A source pointer is added to help client applications report which entity was access denied.

@internal

Hierarchy

Expanded class hierarchy of EntityAccessDeniedHttpExceptionNormalizer

See also

http://jsonapi.org/format/#error-objects

1 string reference to 'EntityAccessDeniedHttpExceptionNormalizer'
jsonapi.services.yml in ./jsonapi.services.yml
jsonapi.services.yml
1 service uses EntityAccessDeniedHttpExceptionNormalizer
serializer.normalizer.entity_access_exception.jsonapi in ./jsonapi.services.yml
Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer

File

src/Normalizer/EntityAccessDeniedHttpExceptionNormalizer.php, line 19

Namespace

Drupal\jsonapi\Normalizer
View source
class EntityAccessDeniedHttpExceptionNormalizer extends HttpExceptionNormalizer {

  /**
   * {@inheritdoc}
   */
  protected $supportedInterfaceOrClass = EntityAccessDeniedHttpException::class;

  /**
   * {@inheritdoc}
   */
  protected function buildErrorObjects(HttpException $exception) {
    $errors = parent::buildErrorObjects($exception);
    if ($exception instanceof EntityAccessDeniedHttpException) {
      $error = $exception
        ->getError();

      /** @var \Drupal\Core\Entity\EntityInterface $entity */
      $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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
EntityAccessDeniedHttpExceptionNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides HttpExceptionNormalizer::$supportedInterfaceOrClass
EntityAccessDeniedHttpExceptionNormalizer::buildErrorObjects protected function Builds the normalized JSON API error objects for the response. Overrides HttpExceptionNormalizer::buildErrorObjects
HttpExceptionNormalizer::$currentUser protected property The current user making the request.
HttpExceptionNormalizer::getInfoUrl public static function Return a string to the common problem type.
HttpExceptionNormalizer::normalize public function Normalizes an object into a set of arrays/scalars.
HttpExceptionNormalizer::__construct public function HttpExceptionNormalizer constructor.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::$formats protected property The formats that the Normalizer can handle. 4
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() Overrides NormalizerBase::supportsDenormalization
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. Overrides NormalizerBase::supportsNormalization