EntityReferenceFieldItemNormalizerTrait.php in Drupal 8
File
core/modules/serialization/src/Normalizer/EntityReferenceFieldItemNormalizerTrait.php
View source
<?php
namespace Drupal\serialization\Normalizer;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
trait EntityReferenceFieldItemNormalizerTrait {
protected function normalizeRootReferenceValue(&$values, EntityReferenceItem $field_item) {
if ($this
->fieldItemReferencesTaxonomyTerm($field_item) && empty($values['target_id'])) {
$values['target_id'] = NULL;
}
}
protected function fieldItemReferencesTaxonomyTerm(EntityReferenceItem $field_item) {
return $field_item
->getFieldDefinition()
->getSetting('target_type') === 'taxonomy_term';
}
}