class ComplexDataNormalizer

Same name in other branches
  1. 8.9.x core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer
  2. 10 core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer
  3. 11.x core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php \Drupal\serialization\Normalizer\ComplexDataNormalizer

Converts the Drupal entity object structures to a normalized array.

This is the default Normalizer for entities. All formats that have Encoders registered with the Serializer in the DIC will be normalized with this class unless another Normalizer is registered which supersedes it. If a module wants to use format-specific or class-specific normalization, then that module can register a new Normalizer and give it a higher priority than this one.

Hierarchy

Expanded class hierarchy of ComplexDataNormalizer

1 file declares its use of ComplexDataNormalizer
ComplexDataNormalizerTest.php in core/modules/serialization/tests/src/Unit/Normalizer/ComplexDataNormalizerTest.php
Contains \Drupal\Tests\serialization\Unit\Normalizer\ComplexDataNormalizerTest.
1 string reference to 'ComplexDataNormalizer'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses ComplexDataNormalizer
serializer.normalizer.complex_data in core/modules/serialization/serialization.services.yml
Drupal\serialization\Normalizer\ComplexDataNormalizer

File

core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php, line 18

Namespace

Drupal\serialization\Normalizer
View source
class ComplexDataNormalizer extends NormalizerBase {
    
    /**
     * {@inheritdoc}
     */
    protected $supportedInterfaceOrClass = ComplexDataInterface::class;
    
    /**
     * {@inheritdoc}
     */
    public function normalize($object, $format = NULL, array $context = []) {
        $attributes = [];
        // $object will not always match $supportedInterfaceOrClass.
        // @see \Drupal\serialization\Normalizer\EntityNormalizer
        // Other normalizers that extend this class may only provide $object that
        // implements \Traversable.
        if ($object instanceof ComplexDataInterface) {
            // If there are no properties to normalize, just normalize the value.
            $object = !empty($object->getProperties(TRUE)) ? TypedDataInternalPropertiesHelper::getNonInternalProperties($object) : $object->getValue();
        }
        
        /** @var \Drupal\Core\TypedData\TypedDataInterface $property */
        foreach ($object as $name => $property) {
            $attributes[$name] = $this->serializer
                ->normalize($property, $format, $context);
        }
        return $attributes;
    }
    
    /**
     * {@inheritdoc}
     */
    public function hasCacheableSupportsMethod() : bool {
        return TRUE;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
ComplexDataNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass 3
ComplexDataNormalizer::hasCacheableSupportsMethod public function Overrides NormalizerBase::hasCacheableSupportsMethod 1
ComplexDataNormalizer::normalize public function 7
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 1
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.