FieldItemNormalizer.php

Same filename in this branch
  1. 8.9.x core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php
  2. 8.9.x core/modules/hal/src/Normalizer/FieldItemNormalizer.php
Same filename in other branches
  1. 9 core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php
  2. 9 core/modules/serialization/src/Normalizer/FieldItemNormalizer.php
  3. 9 core/modules/hal/src/Normalizer/FieldItemNormalizer.php
  4. 10 core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php
  5. 10 core/modules/serialization/src/Normalizer/FieldItemNormalizer.php
  6. 11.x core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php
  7. 11.x core/modules/serialization/src/Normalizer/FieldItemNormalizer.php

Namespace

Drupal\serialization\Normalizer

File

core/modules/serialization/src/Normalizer/FieldItemNormalizer.php

View source
<?php

namespace Drupal\serialization\Normalizer;

use Drupal\Core\Field\FieldItemInterface;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

/**
 * Denormalizes field item object structure by updating the entity field values.
 */
class FieldItemNormalizer extends ComplexDataNormalizer implements DenormalizerInterface {
    use FieldableEntityNormalizerTrait;
    use SerializedColumnNormalizerTrait;
    
    /**
     * {@inheritdoc}
     */
    protected $supportedInterfaceOrClass = FieldItemInterface::class;
    
    /**
     * {@inheritdoc}
     */
    public function denormalize($data, $class, $format = NULL, array $context = []) {
        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;
    }

}

Classes

Title Deprecated Summary
FieldItemNormalizer Denormalizes field item object structure by updating the entity field values.

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