function HttpExceptionNormalizer::normalize
Same name and namespace in other branches
- 10 core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::normalize()
- 11.x core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::normalize()
- 9 core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::normalize()
- 8.9.x core/modules/jsonapi/src/Normalizer/HttpExceptionNormalizer.php \Drupal\jsonapi\Normalizer\HttpExceptionNormalizer::normalize()
Normalizes data into a set of arrays/scalars.
Parameters
mixed $object: Data to normalize.
string|null $format: Format the normalization result will be encoded as.
array<string, mixed> $context: Context options for the normalizer.
Return value
array|string|int|float|bool|\ArrayObject<mixed, mixed>|null \ArrayObject is used to make sure an empty object is encoded as an object not an array.
File
-
core/
modules/ jsonapi/ src/ Normalizer/ HttpExceptionNormalizer.php, line 56
Class
- HttpExceptionNormalizer
- Normalizes an HttpException in compliance with the JSON:API specification.
Namespace
Drupal\jsonapi\NormalizerCode
public function normalize($object, $format = NULL, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
$cacheability = new CacheableMetadata();
if ($object instanceof CacheableDependencyInterface) {
$cacheability->addCacheableDependency($object);
}
else {
$cacheability->setCacheMaxAge(0);
}
$is_verbose_reporting = \Drupal::config('system.logging')->get('error_level') === ERROR_REPORTING_DISPLAY_VERBOSE;
$cacheability->addCacheTags([
'config:system.logging',
]);
$site_report_access = $this->currentUser
->hasPermission('access site reports');
$cacheability->addCacheContexts([
'user.permissions',
]);
if ($site_report_access && $is_verbose_reporting) {
$cacheability->setCacheMaxAge(0);
}
return new HttpExceptionNormalizerValue($cacheability, static::rasterizeValueRecursive($this->buildErrorObjects($object)));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.