function SerializedColumnNormalizerTrait::checkForSerializedStrings

Same name in other branches
  1. 9 core/modules/serialization/src/Normalizer/SerializedColumnNormalizerTrait.php \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait::checkForSerializedStrings()
  2. 8.9.x core/modules/serialization/src/Normalizer/SerializedColumnNormalizerTrait.php \Drupal\serialization\Normalizer\SerializedColumnNormalizerTrait::checkForSerializedStrings()
  3. 11.x 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.

2 calls to SerializedColumnNormalizerTrait::checkForSerializedStrings()
FieldItemNormalizer::denormalize in core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php
FieldItemNormalizer::denormalize in core/modules/serialization/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\Normalizer

Code

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));
    }
}

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