public function Job::setState

Updates the state of the job.

Parameters

int $state: The new state of the job. Has to be one of the job state constants.

string $message: (optional) The log message to be saved along with the state change.

array $variables: (optional) An array of variables to replace in the message on display.

string $type: (optional) The message type.

Return value

int The updated state of the job if it could be set.

Overrides JobInterface::setState

See also

Job::addMessage()

4 calls to Job::setState()
Job::aborted in src/Entity/Job.php
Sets the state of the job to 'aborted'.
Job::finished in src/Entity/Job.php
Set the state of the job to 'finished'.
Job::rejected in src/Entity/Job.php
Sets the state of the job to 'rejected'.
Job::submitted in src/Entity/Job.php
Set the state of the job to 'submitted'.

File

src/Entity/Job.php, line 555

Class

Job
Entity class for the tmgmt_job entity.

Namespace

Drupal\tmgmt\Entity

Code

public function setState($state, $message = NULL, $variables = array(), $type = 'debug') {

  // Return TRUE if the state could be set. Return FALSE otherwise.
  if (array_key_exists($state, Job::getStates())) {
    $this->state = $state;
    $this
      ->save();

    // If a message is attached to this state change add it now.
    if (!empty($message)) {
      $this
        ->addMessage($message, $variables, $type);
    }
  }
  return $this
    ->getState();
}