You are here

public function JobItem::setState in Translation Management Tool 8

Updates the state of the job item.

Parameters

string $state: The new state of the job item. 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) Statically set to status.

Return value

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

Overrides JobItemInterface::setState

See also

Job::addMessage()

5 calls to JobItem::setState()
JobItem::abortTranslation in src/Entity/JobItem.php
Attempts to abort the translation job item.
JobItem::accepted in src/Entity/JobItem.php
Sets the state of the job item to 'accepted'.
JobItem::active in src/Entity/JobItem.php
Sets the state of the job item to 'active'.
JobItem::addTranslatedData in src/Entity/JobItem.php
Adds translated data to a job item.
JobItem::needsReview in src/Entity/JobItem.php
Sets the state of the job item to 'needs review'.

File

src/Entity/JobItem.php, line 551

Class

JobItem
Entity class for the tmgmt_job_item 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, JobItem::getStates()) && $this
    ->get('state')->value != $state) {
    $this
      ->set('state', $state);

    // Changing the state resets the translator state.
    $this
      ->setTranslatorState(NULL);
    $this
      ->save();

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