class EntityAccessDeniedHttpExceptionNormalizer
Same name in other branches
- 8.9.x core/modules/jsonapi/src/Normalizer/EntityAccessDeniedHttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer
- 10 core/modules/jsonapi/src/Normalizer/EntityAccessDeniedHttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer
- 11.x core/modules/jsonapi/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 JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface, \Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\jsonapi\Normalizer\NormalizerBase extends \Drupal\serialization\Normalizer\NormalizerBase
- class \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer extends \Drupal\jsonapi\Normalizer\NormalizerBase
- class \Drupal\jsonapi\Normalizer\EntityAccessDeniedHttpExceptionNormalizer extends \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer
- class \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer extends \Drupal\jsonapi\Normalizer\NormalizerBase
- class \Drupal\jsonapi\Normalizer\NormalizerBase extends \Drupal\serialization\Normalizer\NormalizerBase
Expanded class hierarchy of EntityAccessDeniedHttpExceptionNormalizer
See also
https://www.drupal.org/project/drupal/issues/3032787
http://jsonapi.org/format/#error-objects
1 string reference to 'EntityAccessDeniedHttpExceptionNormalizer'
- jsonapi.services.yml in core/
modules/ jsonapi/ jsonapi.services.yml - core/modules/jsonapi/jsonapi.services.yml
1 service uses EntityAccessDeniedHttpExceptionNormalizer
File
-
core/
modules/ jsonapi/ src/ Normalizer/ EntityAccessDeniedHttpExceptionNormalizer.php, line 24
Namespace
Drupal\jsonapi\NormalizerView 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'];
$relationship_field = $error['relationship_field'] ?? NULL;
if (isset($entity)) {
$entity_type_id = $entity->getEntityTypeId();
$bundle = $entity->bundle();
/** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
$resource_type = \Drupal::service('jsonapi.resource_type.repository')->get($entity_type_id, $bundle);
$resource_type_name = $resource_type->getTypeName();
$route_name = !is_null($relationship_field) ? "jsonapi.{$resource_type_name}.{$relationship_field}.related" : "jsonapi.{$resource_type_name}.individual";
$url = Url::fromRoute($route_name, [
'entity' => $entity->uuid(),
]);
$errors[0]['links']['via']['href'] = $url->setAbsolute()
->toString(TRUE)
->getGeneratedUrl();
}
$errors[0]['source']['pointer'] = $pointer;
if ($reason) {
$errors[0]['detail'] = isset($errors[0]['detail']) ? $errors[0]['detail'] . ' ' . $reason : $reason;
}
}
return $errors;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | 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::hasCacheableSupportsMethod | public | function | Overrides NormalizerBase::hasCacheableSupportsMethod | ||
HttpExceptionNormalizer::normalize | public | function | |||
HttpExceptionNormalizer::__construct | public | function | HttpExceptionNormalizer constructor. | ||
NormalizerBase::$format | protected | property | List of formats which supports (de-)normalization. | Overrides NormalizerBase::$format | |
NormalizerBase::addCacheableDependency | protected | function | Adds cacheability if applicable. | ||
NormalizerBase::checkFormat | protected | function | Checks if the provided format is supported by this normalizer. | Overrides NormalizerBase::checkFormat | |
NormalizerBase::rasterizeValueRecursive | protected static | function | Rasterizes a value recursively. | ||
NormalizerBase::supportsDenormalization | public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 | |
NormalizerBase::supportsNormalization | public | function | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.