class ComplexDataNormalizer in Drupal 9
Same name and namespace in other branches
- 8 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
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\ComplexDataNormalizer
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\NormalizerView 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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableNormalizerInterface:: |
constant | Name of key for bubbling cacheability metadata via serialization context. | ||
ComplexDataNormalizer:: |
protected | property |
The interface or class that this Normalizer supports. Overrides NormalizerBase:: |
3 |
ComplexDataNormalizer:: |
public | function | 7 | |
NormalizerBase:: |
protected | property | List of formats which supports (de-)normalization. | 3 |
NormalizerBase:: |
protected | function | Adds cacheability if applicable. | |
NormalizerBase:: |
protected | function | Checks if the provided format is supported by this normalizer. | 1 |
NormalizerBase:: |
public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 |
NormalizerBase:: |
public | function | 1 |