function EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue

Same name in other branches
  1. 9 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
  2. 8.9.x core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
  3. 11.x core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
1 call to EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
EntityReferenceFieldItemNormalizer::normalize in core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php

File

core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php, line 12

Class

EntityReferenceFieldItemNormalizerTrait
Converts empty reference values for entity reference items.

Namespace

Drupal\serialization\Normalizer

Code

protected function normalizeRootReferenceValue(&$values, EntityReferenceItem $field_item) {
    // @todo Generalize for all tree-structured entity types.
    if ($this->fieldItemReferencesTaxonomyTerm($field_item) && empty($values['target_id'])) {
        $values['target_id'] = NULL;
    }
}

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