function NormalizerBase::rasterizeValueRecursive
Same name in other branches
- 9 core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase::rasterizeValueRecursive()
- 8.9.x core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase::rasterizeValueRecursive()
- 10 core/modules/jsonapi/src/Normalizer/NormalizerBase.php \Drupal\jsonapi\Normalizer\NormalizerBase::rasterizeValueRecursive()
Rasterizes a value recursively.
This is mainly for configuration entities where a field can be a tree of values to rasterize.
Parameters
mixed $value: Either a scalar, an array or a rasterizable object.
Return value
mixed The rasterized value.
2 calls to NormalizerBase::rasterizeValueRecursive()
- FieldItemNormalizer::normalize in core/
modules/ jsonapi/ src/ Normalizer/ FieldItemNormalizer.php - This normalizer leaves JSON:API normalizer land and enters the land of Drupal core's serialization system. That system was never designed with cacheability in mind, and hence bubbles cacheability out of band. This must catch it, and pass it to…
- HttpExceptionNormalizer::normalize in core/
modules/ jsonapi/ src/ Normalizer/ HttpExceptionNormalizer.php
File
-
core/
modules/ jsonapi/ src/ Normalizer/ NormalizerBase.php, line 36
Class
- NormalizerBase
- Base normalizer used in all JSON:API normalizers.
Namespace
Drupal\jsonapi\NormalizerCode
protected static function rasterizeValueRecursive($value) {
if (!$value || is_scalar($value)) {
return $value;
}
if (is_array($value)) {
$output = [];
foreach ($value as $key => $item) {
$output[$key] = static::rasterizeValueRecursive($item);
}
return $output;
}
if ($value instanceof CacheableNormalization) {
return $value->getNormalization();
}
// If the object can be turned into a string it's better than nothing.
if (method_exists($value, '__toString')) {
return $value->__toString();
}
// We give up, since we do not know how to rasterize this.
return NULL;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.