checkForSerializedStrings example

return $normalization;
  }

  /** * {@inheritdoc} */
  public function denormalize($data$class$format = NULL, array $context = []): mixed {
    $item_definition = $context['field_definition']->getItemDefinition();
    assert($item_definition instanceof FieldItemDataDefinitionInterface);

    $field_item = $this->getFieldItemInstance($context['resource_type']$item_definition);
    $this->checkForSerializedStrings($data$class$field_item);

    $property_definitions = $item_definition->getPropertyDefinitions();

    $serialized_property_names = $this->getCustomSerializedPropertyNames($field_item);
    $denormalize_property = function D$property_name$property_value$property_value_class$format$context) use ($serialized_property_names) {
      if ($this->serializer->supportsDenormalization($property_value$property_value_class$format$context)) {
        return $this->serializer->denormalize($property_value$property_value_class$format$context);
      }
      else {
        if (in_array($property_name$serialized_property_names, TRUE)) {
          $property_value = serialize($property_value);
        }
public function denormalize($data$class$format = NULL, array $context = []): mixed {
    if (!isset($context['target_instance'])) {
      throw new InvalidArgumentException('$context[\'target_instance\'] must be set to denormalize with the FieldItemNormalizer');
    }

    if ($context['target_instance']->getParent() == NULL) {
      throw new InvalidArgumentException('The field item passed in via $context[\'target_instance\'] must have a parent set.');
    }

    /** @var \Drupal\Core\Field\FieldItemInterface $field_item */
    $field_item = $context['target_instance'];
    $this->checkForSerializedStrings($data$class$field_item);

    $field_item->setValue($this->constructValue($data$context));
    return $field_item;
  }

  /** * {@inheritdoc} */
  public function getSupportedTypes(?string $format): array {
    return [
      FieldItemInterface::class => TRUE,
    ];
Home | Imprint | This part of the site doesn't use cookies.