You are here

public function EntityReferenceRevisionItemNormalizer::normalize in Entity Reference Revisions 8

Overrides EntityReferenceItemNormalizer::normalize

File

src/Normalizer/EntityReferenceRevisionItemNormalizer.php, line 34

Class

EntityReferenceRevisionItemNormalizer
Defines a class for normalizing EntityReferenceRevisionItems.

Namespace

Drupal\entity_reference_revisions\Normalizer

Code

public function normalize($field_item, $format = NULL, array $context = array()) {
  $data = parent::normalize($field_item, $format, $context);
  $field_name = $field_item
    ->getParent()
    ->getName();
  $entity = $field_item
    ->getEntity();
  $field_uri = $this->linkManager
    ->getRelationUri($entity
    ->getEntityTypeId(), $entity
    ->bundle(), $field_name, $context);
  $data['_embedded'][$field_uri][0]['target_revision_id'] = $field_item->target_revision_id;
  return $data;
}