public function JobItem::accepted in Translation Management Tool 8
Sets the state of the job item to 'accepted'.
Parameters
string $message: Message for the source to be reviewed.
array $variables: (optional) An array of variables to replace in the message on display.
string $type: (optional) Statically set to status.
Overrides JobItemInterface::accepted
1 call to JobItem::accepted()
- JobItem::acceptTranslation in src/
Entity/ JobItem.php - Propagates the returned job item translations to the sources.
File
- src/
Entity/ JobItem.php, line 488
Class
- JobItem
- Entity class for the tmgmt_job_item entity.
Namespace
Drupal\tmgmt\EntityCode
public function accepted($message = NULL, $variables = array(), $type = 'status') {
if (!isset($message)) {
$source_url = $this
->getSourceUrl();
try {
// @todo: Make sure we use the latest revision.
// Fix in https://www.drupal.org/project/tmgmt/issues/2979126.
$translation = \Drupal::entityTypeManager()
->getStorage($this
->getItemType())
->load($this
->getItemId());
} catch (PluginNotFoundException $e) {
$translation = NULL;
}
if (isset($translation) && $translation
->hasTranslation($this
->getJob()
->getTargetLangcode())) {
$translation = $translation
->getTranslation($this
->getJob()
->getTargetLangcode());
try {
$translation_url = $translation
->toUrl();
} catch (UndefinedLinkTemplateException $e) {
$translation_url = NULL;
}
$message = $source_url && $translation_url ? 'The translation for <a href=":source_url">@source</a> has been accepted as <a href=":target_url">@target</a>.' : 'The translation for @source has been accepted as @target.';
$variables = $source_url && $translation_url ? array(
':source_url' => $source_url
->toString(),
'@source' => $this
->getSourceLabel(),
':target_url' => $translation_url
->toString(),
'@target' => $translation ? $translation
->label() : $this
->getSourceLabel(),
) : array(
'@source' => $this
->getSourceLabel(),
'@target' => $translation ? $translation
->label() : $this
->getSourceLabel(),
);
}
else {
$message = $source_url ? 'The translation for <a href=":source_url">@source</a> has been accepted.' : 'The translation for @source has been accepted.';
$variables = $source_url ? array(
':source_url' => $source_url
->toString(),
'@source' => $this
->getSourceLabel(),
) : array(
'@source' => $this
->getSourceLabel(),
);
}
}
$return = $this
->setState(static::STATE_ACCEPTED, $message, $variables, $type);
// Check if this was the last unfinished job item in this job.
$job = $this
->getJob();
if ($job && !$job
->isContinuous() && tmgmt_job_check_finished($this
->getJobId())) {
// Mark the job as finished in case it is a normal job.
$job
->finished();
}
return $return;
}