public function TaxonomyTermNormalizer::normalize in Replication 8
Same name and namespace in other branches
- 8.2 src/Normalizer/TaxonomyTermNormalizer.php \Drupal\replication\Normalizer\TaxonomyTermNormalizer::normalize()
Overrides ContentEntityNormalizer::normalize
File
- src/
Normalizer/ TaxonomyTermNormalizer.php, line 17
Class
Namespace
Drupal\replication\NormalizerCode
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);
}