function EntityReferenceItemNormalizer::constructValue
Same name in other branches
- 9 core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php \Drupal\hal\Normalizer\EntityReferenceItemNormalizer::constructValue()
Overrides FieldableEntityNormalizerTrait::constructValue
File
-
core/
modules/ hal/ src/ Normalizer/ EntityReferenceItemNormalizer.php, line 147
Class
- EntityReferenceItemNormalizer
- Converts the Drupal entity reference item object to HAL array structure.
Namespace
Drupal\hal\NormalizerCode
protected function constructValue($data, $context) {
$field_item = $context['target_instance'];
$field_definition = $field_item->getFieldDefinition();
$target_type = $field_definition->getSetting('target_type');
$id = $this->entityResolver
->resolve($this, $data, $target_type);
if (isset($id)) {
return [
'target_id' => $id,
] + array_intersect_key($data, $field_item->getProperties());
}
return NULL;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.