You are here

public function EntityReferenceLayoutItemNormalizer::normalize in Entity Reference with Layout 8

Overrides EntityReferenceItemNormalizer::normalize

File

src/Normalizer/EntityReferenceLayoutItemNormalizer.php, line 34

Class

EntityReferenceLayoutItemNormalizer
Defines a class for normalizing EntityReferenceLayoutItems.

Namespace

Drupal\entity_reference_layout\Normalizer

Code

public function normalize($field_item, $format = NULL, array $context = []) {

  /** @var \Drupal\Core\Field\FieldItemInterface $field_item */
  $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;
  $data['_embedded'][$field_uri][0]['region'] = $field_item->region;
  $data['_embedded'][$field_uri][0]['layout'] = $field_item->layout;
  $data['_embedded'][$field_uri][0]['section_id'] = $field_item->section_id;
  $data['_embedded'][$field_uri][0]['options'] = $field_item->options;
  $data['_embedded'][$field_uri][0]['config'] = $field_item->config;
  return $data;
}