You are here

trait GeysirFormEntityRevisionTrait in Geysir 8

Provides the geysir forms entity revisions support.

@package Drupal\geysir\Form

Hierarchy

File

src/Form/GeysirFormEntityRevisionTrait.php, line 17

Namespace

Drupal\geysir\Form
View source
trait GeysirFormEntityRevisionTrait {

  /**
   * Saves the revision on the parent entity.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The parent entity.
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The system time.
   * @param \Drupal\Core\Session\AccountInterface $current_user
   *   The current user.
   *
   * @return int
   *   Save status.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  protected function saveParentEntityRevision(EntityInterface $entity, TimeInterface $time, AccountInterface $current_user) : int {
    if ($entity instanceof RevisionableInterface) {
      $entity
        ->setNewRevision();
      if ($entity instanceof TranslatableRevisionableInterface) {
        $entity
          ->setRevisionTranslationAffected(TRUE);
      }
      if ($entity instanceof RevisionLogInterface) {
        $entity
          ->setRevisionCreationTime($time
          ->getRequestTime());
        $entity
          ->setRevisionUserId($current_user
          ->id());
      }
    }
    return $entity
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GeysirFormEntityRevisionTrait::saveParentEntityRevision protected function Saves the revision on the parent entity.