subject = $subject; $this->entityTypeManager = $entity_type_manager; $this->enhancerManager = $enhancer_manager; } /** * {@inheritdoc} */ public function normalize($object, $format = NULL, array $context = []) { // First get the regular output. $normalized_output = $this->subject->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_type']; $enhancer = $resource_type->getFieldEnhancer($object->getParent()->getName()); if (!$enhancer) { return $normalized_output; } // Apply any enhancements necessary. $processed = $enhancer->postProcess($normalized_output->rasterizeValue()); $normalized_output = new FieldItemNormalizerValue([$processed]); return $normalized_output; } }