protected function DynamicEntityReferenceItemNormalizer::constructValue in Dynamic Entity Reference 8
Same name and namespace in other branches
- 8.2 src/Normalizer/DynamicEntityReferenceItemNormalizer.php \Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer::constructValue()
Build the field item value using the incoming data.
Most normalizers that extend this class can simply use this method to construct the denormalized value without having to override denormalize() and reimplementing its validation logic or its call to set the field value.
It's recommended to not override this and instead provide a (de)normalizer at the DataType level.
Parameters
mixed $data: The incoming data for this field item.
array $context: The context passed into the Normalizer.
Return value
mixed The value to use in Entity::setValue().
Overrides EntityReferenceItemNormalizer::constructValue
File
- src/
Normalizer/ DynamicEntityReferenceItemNormalizer.php, line 32
Class
- DynamicEntityReferenceItemNormalizer
- Dynamic entity reference normalizer.
Namespace
Drupal\dynamic_entity_reference\NormalizerCode
protected function constructValue($data, $context) {
if ($id = $this->entityResolver
->resolve($this, $data, $data['target_type'])) {
return [
'target_type' => $data['target_type'],
'target_id' => $id,
];
}
return NULL;
}