PrimitiveDataNormalizer.php in Drupal 9
File
core/modules/serialization/src/Normalizer/PrimitiveDataNormalizer.php
View source
<?php
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\TypedData\PrimitiveInterface;
class PrimitiveDataNormalizer extends NormalizerBase {
use SerializedColumnNormalizerTrait;
protected $supportedInterfaceOrClass = PrimitiveInterface::class;
public function normalize($object, $format = NULL, array $context = []) {
$this
->addCacheableDependency($context, $object);
$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());
}
}
return $object
->getValue() === NULL ? NULL : $object
->getCastedValue();
}
}