You are here

protected function WorkflowTransitionRevertForm::prepareRevertedTransition in Workflow 8

Prepares a transition to be reverted.

Parameters

\Drupal\workflow\Entity\WorkflowTransitionInterface $transition: The transition to be reverted.

Return value

\Drupal\workflow\Entity\WorkflowTransitionInterface The prepared transition ready to be stored.

1 call to WorkflowTransitionRevertForm::prepareRevertedTransition()
WorkflowTransitionRevertForm::submitForm in src/Form/WorkflowTransitionRevertForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…

File

src/Form/WorkflowTransitionRevertForm.php, line 115

Class

WorkflowTransitionRevertForm
Implements a form to revert an entity to a previous state.

Namespace

Drupal\workflow\Form

Code

protected function prepareRevertedTransition(WorkflowTransitionInterface $transition) {
  $user = \Drupal::currentUser();
  $entity = $transition
    ->getTargetEntity();
  $field_name = $transition
    ->getFieldName();
  $current_sid = workflow_node_current_state($entity, $field_name);
  $previous_sid = $transition
    ->getFromSid();
  $comment = $this
    ->t('State reverted.');
  $transition = WorkflowTransition::create([
    $current_sid,
    'field_name' => $field_name,
  ]);
  $transition
    ->setTargetEntity($entity);
  $time = \Drupal::time()
    ->getRequestTime();
  $transition
    ->setValues($previous_sid, $user
    ->id(), $time, $comment);
  return $transition;
}