public function Paragraph::getParentEntity in Paragraphs 8
Gets the parent entity of the paragraph.
Preserves language context with translated entities.
Return value
ContentEntityInterface The parent entity.
Overrides ParagraphInterface::getParentEntity
4 calls to Paragraph::getParentEntity()
- Paragraph::getOwner in src/
Entity/ Paragraph.php - Paragraph::getOwnerId in src/
Entity/ Paragraph.php - Paragraph::getRevisionAuthor in src/
Entity/ Paragraph.php - Paragraph::label in src/
Entity/ Paragraph.php - Gets the label of the entity.
File
- src/
Entity/ Paragraph.php, line 123
Class
- Paragraph
- Defines the Paragraph entity.
Namespace
Drupal\paragraphs\EntityCode
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;
}