public function Paragraph::getParentEntity

Gets the parent entity of the paragraph.

Preserves language context with translated entities.

Return value

\Drupal\Core\Entity\ContentEntityInterface|null The parent entity.

Overrides ParagraphInterface::getParentEntity

4 calls to Paragraph::getParentEntity()
Paragraph::getOwner in paragraphs/src/Entity/Paragraph.php
Paragraph::getOwnerId in paragraphs/src/Entity/Paragraph.php
Paragraph::getRevisionAuthor in paragraphs/src/Entity/Paragraph.php
Paragraph::label in paragraphs/src/Entity/Paragraph.php

File

paragraphs/src/Entity/Paragraph.php, line 123

Class

Paragraph
Defines the Paragraph entity.

Namespace

Drupal\paragraphs\Entity

Code

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;
}