You are here

public function CropNormalizer::normalize in Replication 8

Overrides ContentEntityNormalizer::normalize

File

src/Normalizer/CropNormalizer.php, line 17

Class

CropNormalizer

Namespace

Drupal\replication\Normalizer

Code

public function normalize($entity, $format = NULL, array $context = []) {
  $data = parent::normalize($entity, $format, $context);
  $cropped_entity_type_id = $entity->entity_type->value;
  $cropped_entity_storage = $this->entityManager
    ->getStorage($cropped_entity_type_id);
  $cropped_entity = $cropped_entity_storage
    ->load($entity->entity_id->value);
  $entity_languages = $entity
    ->getTranslationLanguages();
  foreach ($entity_languages as $entity_language) {

    // Store all needed information about entity referenced by 'entity_id' field.
    $data[$entity_language
      ->getId()]['entity_id'][0]['crop_target_uuid'] = $cropped_entity
      ->uuid();
    $data[$entity_language
      ->getId()]['entity_id'][0]['crop_target_entity_type_id'] = $cropped_entity
      ->getEntityTypeId();
    $data[$entity_language
      ->getId()]['entity_id'][0]['crop_target_bundle'] = $cropped_entity
      ->bundle();
  }
  return $data;
}