You are here

public function ContentEntityBase::postSave in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::postSave()
  2. 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::postSave()

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides EntityBase::postSave

4 methods override ContentEntityBase::postSave()
BlockContent::postSave in core/modules/block_content/src/Entity/BlockContent.php
Acts on a saved entity before the insert or update hook is invoked.
Media::postSave in core/modules/media/src/Entity/Media.php
Acts on a saved entity before the insert or update hook is invoked.
MenuLinkContent::postSave in core/modules/menu_link_content/src/Entity/MenuLinkContent.php
Acts on a saved entity before the insert or update hook is invoked.
PathAlias::postSave in core/modules/path_alias/src/Entity/PathAlias.php
Acts on a saved entity before the insert or update hook is invoked.

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 462

Class

ContentEntityBase
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  parent::postSave($storage, $update);

  // Update the status of all saved translations.
  $removed = [];
  foreach ($this->translations as $langcode => &$data) {
    if ($data['status'] == static::TRANSLATION_REMOVED) {
      $removed[$langcode] = TRUE;
    }
    else {
      $data['status'] = static::TRANSLATION_EXISTING;
    }
  }
  $this->translations = array_diff_key($this->translations, $removed);

  // Reset the new revision flag.
  $this->newRevision = FALSE;

  // Reset the enforcement of the revision translation affected flag.
  $this->enforceRevisionTranslationAffected = [];
}