Unverified Commit ef0714c6 authored by Siegrist's avatar Siegrist Committed by e0ipso

Issue #3077186 by Siegrist, e0ipso: Pass context in ResouceObjectNormalizer

parent ea197cc0
......@@ -6,6 +6,7 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\jsonapi\JsonApiResource\ResourceObject;
use Drupal\jsonapi\Normalizer\Value\CacheableNormalization;
use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType;
use Shaper\Util\Context;
/**
* Decorates the JSON:API ResourceObjectNormalizer.
......@@ -25,7 +26,7 @@ class ResourceObjectNormalizer extends JsonApiNormalizerDecoratorBase {
if (is_subclass_of($resource_type->getDeserializationTargetClass(), ConfigEntityInterface::class)) {
return new CacheableNormalization(
$cacheable_normalization,
static::enhanceConfigFields($cacheable_normalization->getNormalization(), $resource_type)
static::enhanceConfigFields($object, $cacheable_normalization->getNormalization(), $resource_type)
);
}
return $cacheable_normalization;
......@@ -34,6 +35,8 @@ class ResourceObjectNormalizer extends JsonApiNormalizerDecoratorBase {
/**
* Applies field enhancers to a config entity normalization.
*
* @param mixed $object
* The parent object.
* @param array $normalization
* The normalization to be enhanced.
* @param \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type
......@@ -42,14 +45,15 @@ class ResourceObjectNormalizer extends JsonApiNormalizerDecoratorBase {
* @return array
* The enhanced field data.
*/
protected static function enhanceConfigFields(array $normalization, ConfigurableResourceType $resource_type) {
protected static function enhanceConfigFields($object, array $normalization, ConfigurableResourceType $resource_type) {
if (!empty($normalization['attributes'])) {
foreach ($normalization['attributes'] as $field_name => $field_value) {
$enhancer = $resource_type->getFieldEnhancer($field_name);
if (!$enhancer) {
continue;
}
$normalization['attributes'][$field_name] = $enhancer->undoTransform($field_value);
$context['field_item_object'] = $object;
$normalization['attributes'][$field_name] = $enhancer->undoTransform($field_value, new Context($context));
}
}
return $normalization;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment