protected function SerializedColumnNormalizerTrait::checkForSerializedStrings in Drupal 9
Same name and namespace in other branches
- 8 core/modules/serialization/src/Normalizer/SerializedColumnNormalizerTrait.php \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait::checkForSerializedStrings()
Checks if there is a serialized string for a column.
Parameters
mixed $data: The field item data to denormalize.
string $class: The expected class to instantiate.
\Drupal\Core\Field\FieldItemInterface $field_item: The field item.
3 calls to SerializedColumnNormalizerTrait::checkForSerializedStrings()
- FieldItemNormalizer::denormalize in core/
modules/ serialization/ src/ Normalizer/ FieldItemNormalizer.php - FieldItemNormalizer::denormalize in core/
modules/ jsonapi/ src/ Normalizer/ FieldItemNormalizer.php - FieldItemNormalizer::denormalize in core/
modules/ hal/ src/ Normalizer/ FieldItemNormalizer.php
File
- core/
modules/ serialization/ src/ Normalizer/ SerializedColumnNormalizerTrait.php, line 23
Class
- SerializedColumnNormalizerTrait
- A trait providing methods for serialized columns.
Namespace
Drupal\serialization\NormalizerCode
protected function checkForSerializedStrings($data, $class, FieldItemInterface $field_item) {
// Require specialized denormalizers for fields with 'serialize' columns.
// Note: this cannot be checked in ::supportsDenormalization() because at
// that time we only have the field item class. ::hasSerializeColumn()
// must be able to call $field_item->schema(), which requires a field
// storage definition. To determine that, the entity type and bundle
// must be known, which is contextual information that the Symfony
// serializer does not pass to ::supportsDenormalization().
if (!is_array($data)) {
$data = [
$field_item
->getDataDefinition()
->getMainPropertyName() => $data,
];
}
if ($this
->dataHasStringForSerializeColumn($field_item, $data)) {
$field_name = $field_item
->getParent() ? $field_item
->getParent()
->getName() : $field_item
->getName();
throw new \LogicException(sprintf('The generic FieldItemNormalizer cannot denormalize string values for "%s" properties of the "%s" field (field item class: %s).', implode('", "', $this
->getSerializedPropertyNames($field_item)), $field_name, $class));
}
}