You are here

protected function EntityReferenceItemNormalizer::constructValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php \Drupal\hal\Normalizer\EntityReferenceItemNormalizer::constructValue()

Build the field item value using the incoming data.

Parameters

$data: The incoming data for this field item.

$context: The context passed into the Normalizer.

Return value

mixed The value to use in Entity::setValue().

Overrides FieldItemNormalizer::constructValue

File

core/modules/hal/src/Normalizer/EntityReferenceItemNormalizer.php, line 102
Contains \Drupal\hal\Normalizer\EntityReferenceItemNormalizer.

Class

EntityReferenceItemNormalizer
Converts the Drupal entity reference item object to HAL array structure.

Namespace

Drupal\hal\Normalizer

Code

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 array(
      'target_id' => $id,
    );
  }
  return NULL;
}