You are here

protected function EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
  2. 10 core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php \Drupal\serialization\Normalizer\EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
2 calls to EntityReferenceFieldItemNormalizerTrait::normalizeRootReferenceValue()
EntityReferenceFieldItemNormalizer::normalize in core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizer.php
EntityReferenceItemNormalizer::normalizedFieldValues in core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php
Normalizes field values for an item.

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