function FieldItemNormalizer::denormalize

Same name in this branch
  1. 9 core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi\Normalizer\FieldItemNormalizer::denormalize()
  2. 9 core/modules/serialization/src/Normalizer/FieldItemNormalizer.php \Drupal\serialization\Normalizer\FieldItemNormalizer::denormalize()
Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi\Normalizer\FieldItemNormalizer::denormalize()
  2. 8.9.x core/modules/serialization/src/Normalizer/FieldItemNormalizer.php \Drupal\serialization\Normalizer\FieldItemNormalizer::denormalize()
  3. 8.9.x core/modules/hal/src/Normalizer/FieldItemNormalizer.php \Drupal\hal\Normalizer\FieldItemNormalizer::denormalize()
  4. 10 core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi\Normalizer\FieldItemNormalizer::denormalize()
  5. 10 core/modules/serialization/src/Normalizer/FieldItemNormalizer.php \Drupal\serialization\Normalizer\FieldItemNormalizer::denormalize()
  6. 11.x core/modules/jsonapi/src/Normalizer/FieldItemNormalizer.php \Drupal\jsonapi\Normalizer\FieldItemNormalizer::denormalize()
  7. 11.x core/modules/serialization/src/Normalizer/FieldItemNormalizer.php \Drupal\serialization\Normalizer\FieldItemNormalizer::denormalize()

File

core/modules/hal/src/Normalizer/FieldItemNormalizer.php, line 41

Class

FieldItemNormalizer
Converts the Drupal field item object structure to HAL array structure.

Namespace

Drupal\hal\Normalizer

Code

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.');
    }
    $field_item = $context['target_instance'];
    $this->checkForSerializedStrings($data, $class, $field_item);
    // If this field is translatable, we need to create a translated instance.
    if (isset($data['lang'])) {
        $langcode = $data['lang'];
        unset($data['lang']);
        $field_definition = $field_item->getFieldDefinition();
        if ($field_definition->isTranslatable()) {
            $field_item = $this->createTranslatedInstance($field_item, $langcode);
        }
    }
    $field_item->setValue($this->constructValue($data, $context));
    return $field_item;
}

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