Gets the parent entity of the paragraph.
Preserves language context with translated entities.
\Drupal\Core\Entity\ContentEntityInterface|null The parent entity.
Overrides ParagraphInterface::getParentEntity
public function getParentEntity() {
if (!isset($this
->get('parent_type')->value) || !isset($this
->get('parent_id')->value)) {
return NULL;
}
$parent = \Drupal::entityTypeManager()
->getStorage($this
->get('parent_type')->value)
->load($this
->get('parent_id')->value);
// Return current translation of parent entity, if it exists.
if ($parent != NULL && $parent instanceof TranslatableInterface && $parent
->hasTranslation($this
->language()
->getId())) {
return $parent
->getTranslation($this
->language()
->getId());
}
return $parent;
}