You are here

protected function QuickTransitionForm::prepareNewRevision in Moderation Sidebar 8

Prepares a new revision of a given entity, if applicable.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: An entity.

string|\Drupal\Core\StringTranslation\TranslatableMarkup $message: A revision log message to set.

Return value

\Drupal\Core\Entity\EntityInterface The moderation state for the given entity.

2 calls to QuickTransitionForm::prepareNewRevision()
QuickTransitionForm::discardDraft in src/Form/QuickTransitionForm.php
Form submission handler to discard the current draft.
QuickTransitionForm::submitForm in src/Form/QuickTransitionForm.php
Form submission handler.

File

src/Form/QuickTransitionForm.php, line 285

Class

QuickTransitionForm
The QuickTransitionForm provides quick buttons for changing transitions.

Namespace

Drupal\moderation_sidebar\Form

Code

protected function prepareNewRevision(EntityInterface $entity, $message) {
  $storage = $this->entityTypeManager
    ->getStorage($entity
    ->getEntityTypeId());
  if ($storage instanceof ContentEntityStorageInterface) {
    $revision = $storage
      ->createRevision($entity);
    if ($revision instanceof RevisionLogInterface) {
      $revision
        ->setRevisionLogMessage($message);
      $revision
        ->setRevisionCreationTime(\Drupal::time()
        ->getRequestTime());
      $revision
        ->setRevisionUserId($this
        ->currentUser()
        ->id());
    }
    return $revision;
  }
  return $entity;
}