You are here

public function TaxonomyTermNormalizer::normalize in Replication 8.2

Same name and namespace in other branches
  1. 8 src/Normalizer/TaxonomyTermNormalizer.php \Drupal\replication\Normalizer\TaxonomyTermNormalizer::normalize()

Overrides ContentEntityNormalizer::normalize

File

src/Normalizer/TaxonomyTermNormalizer.php, line 17

Class

TaxonomyTermNormalizer

Namespace

Drupal\replication\Normalizer

Code

public function normalize($entity, $format = NULL, array $context = []) {
  $storage = $this->entityManager
    ->getStorage($entity
    ->getEntityTypeId());
  if (!isset($entity->parent->target_id)) {
    $parents = $storage
      ->loadParents($entity
      ->id());
    $parent = reset($parents);
    if ($parent instanceof TermInterface) {
      $entity->parent->target_id = $parent
        ->id();
    }
    else {
      $entity->parent->target_id = 0;
    }
  }
  return parent::normalize($entity, $format, $context);
}