/** * {@inheritdoc} */ public static function executeTransition(WorkflowTransitionInterface $transition, $force = FALSE) { if ($force) { $transition->force($force); } $update_entity = !$transition->isScheduled() && !$transition->isExecuted(); // Validate transition, save in history table and delete from schedule table. $to_sid = $transition->execute(); // Save the (scheduled) transition. if ($update_entity) { if ($to_sid == $transition->getToSid()) { // Update the workflow field of the entity. $transition->updateTargetEntity(); } else { // The transition was not allowed. // @todo: validateForm(). } } else { // We create a new transition, or update an existing one. // Do not update the entity itself. } return $to_sid; }
/** * Prepares a transition to be reverted. * * @param \Drupal\workflow\Entity\WorkflowTransitionInterface $transition * The transition to be reverted. * * @return \Drupal\workflow\Entity\WorkflowTransitionInterface * The prepared transition ready to be stored. */ 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 = t('State reverted.'); $transition = WorkflowTransition::create([$current_sid, 'field_name' => $field_name]); $transition->setTargetEntity($entity); $transition->setValues($previous_sid, $user->id(), REQUEST_TIME, $comment); return $transition; }