public function FieldItemNormalizer::normalize in JSON:API Extras 8.3
Same name and namespace in other branches
- 8 src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi_extras\Normalizer\FieldItemNormalizer::normalize()
- 8.2 src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi_extras\Normalizer\FieldItemNormalizer::normalize()
Overrides JsonApiNormalizerDecoratorBase::normalize
File
- src/
Normalizer/ FieldItemNormalizer.php, line 50
Class
- FieldItemNormalizer
- Converts the Drupal field structure to a JSON:API array structure.
Namespace
Drupal\jsonapi_extras\NormalizerCode
public function normalize($object, $format = NULL, array $context = []) {
// First get the regular output.
$normalized_output = parent::normalize($object, $format, $context);
// Then detect if there is any enhancer to be applied here.
/** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */
$resource_type = $context['resource_object']
->getResourceType();
$enhancer = $resource_type
->getFieldEnhancer($object
->getParent()
->getName());
if (!$enhancer) {
return $normalized_output;
}
// Apply any enhancements necessary.
$context['field_item_object'] = $object;
$processed = $enhancer
->undoTransform($normalized_output
->getNormalization(), new Context($context));
$cacheability = CacheableMetadata::createFromObject($normalized_output)
->addCacheTags([
'config:jsonapi_resource_config_list',
]);
$normalized_output = new CacheableNormalization($cacheability, $processed);
return $normalized_output;
}