onPresave example

->getState($entity->moderation_state->value);

      // This entity is default if it is new, the default revision, or the       // default revision is not published.       $update_default_revision = $entity->isNew()
        || $current_state->isDefaultRevisionState()
        || !$this->moderationInfo->isDefaultRevisionPublished($entity);

      // Fire per-entity-type logic for handling the save process.       $this->entityTypeManager
        ->getHandler($entity->getEntityTypeId(), 'moderation')
        ->onPresave($entity$update_default_revision$current_state->isPublishedState());
    }
  }

  /** * @param \Drupal\Core\Entity\EntityInterface $entity * The entity that was just saved. * * @see hook_entity_insert() */
  public function entityInsert(EntityInterface $entity) {
    if ($this->moderationInfo->isModeratedEntity($entity)) {
      
Home | Imprint | This part of the site doesn't use cookies.