You are here

public function WorkflowTransition::setValues in Workflow 8

Helper function for __construct. Used for all children of WorkflowTransition (aka WorkflowScheduledTransition)

Usage: $transition = WorkflowTransition::create([$current_sid, 'field_name' => $field_name]); $transition->setTargetEntity($entity); $transition->setValues($new_sid, $user->id(), REQUEST_TIME, $comment);

Parameters

string $to_sid:

int $uid:

int $timestamp:

string $comment:

bool $force_create:

Overrides WorkflowTransitionInterface::setValues

1 call to WorkflowTransition::setValues()
WorkflowScheduledTransition::setValues in src/Entity/WorkflowScheduledTransition.php
Helper function for __construct. Used for all children of WorkflowTransition (aka WorkflowScheduledTransition)
1 method overrides WorkflowTransition::setValues()
WorkflowScheduledTransition::setValues in src/Entity/WorkflowScheduledTransition.php
Helper function for __construct. Used for all children of WorkflowTransition (aka WorkflowScheduledTransition)

File

src/Entity/WorkflowTransition.php, line 179

Class

WorkflowTransition
Implements an actual, executed, Transition.

Namespace

Drupal\workflow\Entity

Code

public function setValues($to_sid, $uid = NULL, $timestamp = NULL, $comment = '', $force_create = FALSE) {

  // Normally, the values are passed in an array, and set in parent::__construct, but we do it ourselves.
  $uid = $uid === NULL ? workflow_current_user()
    ->id() : $uid;
  $from_sid = $this
    ->getFromSid();
  $this
    ->set('to_sid', $to_sid);
  $this
    ->setOwnerId($uid);
  $this
    ->setTimestamp($timestamp == NULL ? \Drupal::time()
    ->getRequestTime() : $timestamp);
  $this
    ->setComment($comment);

  // If constructor is called with new() and arguments.
  if (!$from_sid && !$to_sid && !$this
    ->getTargetEntity()) {

    // If constructor is called without arguments, e.g., loading from db.
  }
  elseif ($from_sid && $this
    ->getTargetEntity()) {

    // Caveat: upon entity_delete, $to_sid is '0'.
    // If constructor is called with new() and arguments.
  }
  elseif (!$from_sid) {

    // Not all parameters are passed programmatically.
    if (!$force_create) {
      $this
        ->messenger()
        ->addError($this
        ->t('Wrong call to constructor Workflow*Transition(%from_sid to %to_sid)', [
        '%from_sid' => $from_sid,
        '%to_sid' => $to_sid,
      ]));
    }
  }
  return $this;
}