class PrimitiveDataNormalizer
Same name in other branches
- 9 core/modules/serialization/src/Normalizer/PrimitiveDataNormalizer.php \Drupal\serialization\Normalizer\PrimitiveDataNormalizer
- 10 core/modules/serialization/src/Normalizer/PrimitiveDataNormalizer.php \Drupal\serialization\Normalizer\PrimitiveDataNormalizer
- 11.x core/modules/serialization/src/Normalizer/PrimitiveDataNormalizer.php \Drupal\serialization\Normalizer\PrimitiveDataNormalizer
Converts primitive data objects to their casted values.
Hierarchy
- class \Drupal\serialization\Normalizer\NormalizerBase implements \Symfony\Component\Serializer\SerializerAwareInterface, \Drupal\serialization\Normalizer\CacheableNormalizerInterface uses \Symfony\Component\Serializer\SerializerAwareTrait
- class \Drupal\serialization\Normalizer\PrimitiveDataNormalizer extends \Drupal\serialization\Normalizer\NormalizerBase uses \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait
Expanded class hierarchy of PrimitiveDataNormalizer
1 file declares its use of PrimitiveDataNormalizer
- PrimitiveDataNormalizerTest.php in core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ PrimitiveDataNormalizerTest.php
1 string reference to 'PrimitiveDataNormalizer'
- serialization.services.yml in core/
modules/ serialization/ serialization.services.yml - core/modules/serialization/serialization.services.yml
1 service uses PrimitiveDataNormalizer
- serializer.normalizer.primitive_data in core/
modules/ serialization/ serialization.services.yml - Drupal\serialization\Normalizer\PrimitiveDataNormalizer
File
-
core/
modules/ serialization/ src/ Normalizer/ PrimitiveDataNormalizer.php, line 11
Namespace
Drupal\serialization\NormalizerView source
class PrimitiveDataNormalizer extends NormalizerBase {
use SerializedColumnNormalizerTrait;
/**
* {@inheritdoc}
*/
protected $supportedInterfaceOrClass = PrimitiveInterface::class;
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
$parent = $object->getParent();
if ($parent instanceof FieldItemInterface && $object->getValue()) {
$serialized_property_names = $this->getCustomSerializedPropertyNames($parent);
if (in_array($object->getName(), $serialized_property_names, TRUE)) {
return unserialize($object->getValue());
}
}
// Typed data casts NULL objects to their empty variants, so for example
// the empty string ('') for string type data, or 0 for integer typed data.
// In a better world with typed data implementing algebraic data types,
// getCastedValue would return NULL, but as typed data is not aware of real
// optional values on the primitive level, we implement our own optional
// value normalization here.
return $object->getValue() === NULL ? NULL : $object->getCastedValue();
}
}
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. | |||
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. | 2 | |
NormalizerBase::supportsDenormalization | public | function | Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() | 1 | |
NormalizerBase::supportsNormalization | public | function | 1 | ||
PrimitiveDataNormalizer::$supportedInterfaceOrClass | protected | property | The interface or class that this Normalizer supports. | Overrides NormalizerBase::$supportedInterfaceOrClass | |
PrimitiveDataNormalizer::normalize | public | function | |||
SerializedColumnNormalizerTrait::checkForSerializedStrings | protected | function | Checks if there is a serialized string for a column. | ||
SerializedColumnNormalizerTrait::dataHasStringForSerializeColumn | protected | function | Checks if the data contains string value for serialize column. | ||
SerializedColumnNormalizerTrait::getCustomSerializedPropertyNames | protected | function | Gets the names of all properties the plugin treats as serialized data. | ||
SerializedColumnNormalizerTrait::getSerializedPropertyNames | protected | function | Gets the names of all serialized properties. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.