class ResourceObjectNormalizer in JSON:API Extras 8.3
Decorates the JSON:API ResourceObjectNormalizer.
@internal
Hierarchy
- class \Drupal\jsonapi_extras\Normalizer\JsonApiNormalizerDecoratorBase implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface, \Symfony\Component\Serializer\Normalizer\DenormalizerInterface, \Symfony\Component\Serializer\SerializerAwareInterface
- class \Drupal\jsonapi_extras\Normalizer\ResourceObjectNormalizer
Expanded class hierarchy of ResourceObjectNormalizer
1 file declares its use of ResourceObjectNormalizer
- ResourceObjectNormalizerImpostor.php in src-impostor-normalizers/
ResourceObjectNormalizerImpostor.php
File
- src/
Normalizer/ ResourceObjectNormalizer.php, line 16
Namespace
Drupal\jsonapi_extras\NormalizerView source
class ResourceObjectNormalizer extends JsonApiNormalizerDecoratorBase {
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
assert($object instanceof ResourceObject);
$resource_type = $object
->getResourceType();
$cacheable_normalization = parent::normalize($object, $format, $context);
assert($cacheable_normalization instanceof CacheableNormalization);
if (is_subclass_of($resource_type
->getDeserializationTargetClass(), ConfigEntityInterface::class)) {
return new CacheableNormalization($cacheable_normalization, static::enhanceConfigFields($object, $cacheable_normalization
->getNormalization(), $resource_type));
}
return $cacheable_normalization;
}
/**
* 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
* The resource type of the normalized resource object.
*
* @return array
* The enhanced field data.
*/
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;
}
$context['field_item_object'] = $object;
$normalization['attributes'][$field_name] = $enhancer
->undoTransform($field_value, new Context($context));
}
}
return $normalization;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonApiNormalizerDecoratorBase:: |
protected | property | The decorated (de)normalizer. | |
JsonApiNormalizerDecoratorBase:: |
public | function | Denormalizes data back into an object of the given class. | 2 |
JsonApiNormalizerDecoratorBase:: |
public | function | Sets the owning Serializer object. | |
JsonApiNormalizerDecoratorBase:: |
public | function | Checks whether the given class is supported for denormalization by this normalizer. | |
JsonApiNormalizerDecoratorBase:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. | |
JsonApiNormalizerDecoratorBase:: |
public | function | JsonApiNormalizerDecoratorBase constructor. | 2 |
ResourceObjectNormalizer:: |
protected static | function | Applies field enhancers to a config entity normalization. | |
ResourceObjectNormalizer:: |
public | function |
Normalizes an object into a set of arrays/scalars. Overrides JsonApiNormalizerDecoratorBase:: |