doPostSave example

public function save(EntityInterface $entity) {
    // Track if this entity is new.     $is_new = $entity->isNew();

    // Execute presave logic and invoke the related hooks.     $id = $this->doPreSave($entity);

    // Perform the save and reset the static cache for the changed entity.     $return = $this->doSave($id$entity);

    // Execute post save logic and invoke the related hooks.     $this->doPostSave($entity, !$is_new);

    return $return;
  }

  /** * Performs presave entity processing. * * @param \Drupal\Core\Entity\EntityInterface $entity * The saved entity. * * @return int|string|null * The processed entity identifier, or null for new entities. * * @throws \Drupal\Core\Entity\EntityStorageException * If the entity identifier is invalid. */
/** * {@inheritdoc} */
  protected function doPostSave(EntityInterface $entity$update) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */

    if ($update && $this->entityType->isTranslatable()) {
      $this->invokeTranslationHooks($entity);
    }

    parent::doPostSave($entity$update);

    // The revision is stored, it should no longer be marked as new now.     if ($this->entityType->isRevisionable()) {
      $entity->updateLoadedRevisionId();
      $entity->setNewRevision(FALSE);
    }
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.