Can't use getParentEntity() in hook_entity_insert()? When is the parent entity set?

Created on 20 February 2017, almost 8 years ago
Updated 30 March 2023, over 1 year ago

I need to do some processing after a new paragraph is saved, using the paragraph's parent entity. If I do this:

/**
 * Implements hook_ENTITY_TYPE_insert().
 */
function MYMODULE_paragraph_insert(EntityInterface $entity) {
  $parent = $entity->getParentEntity();
}

$parent is NULL. When is getParentEntity() available?

💬 Support request
Status

Needs review

Version

1.0

Component

Code

Created by

🇳🇿New Zealand john pitcairn

Live updates comments and jobs are added and updated live.
  • Needs documentation

    A documentation change is requested elsewhere. For Drupal core (and possibly other projects), once the change has been committed, this status should be recorded in a change record node.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The problem is not solved. Unable to get parent object on insert.
    In other hooks, it is impossible to determine whether the first one is saving or not.

    One solution is to add a $parentEntity property to the paragraph object and return the parent entity from that property whenever possible.
    But I don't know if this solution has disadvantages.

  • Status changed to Needs review over 1 year ago
Production build 0.71.5 2024