Adds an item to the translation job.
string $plugin: The plugin name.
string $item_type: The source item type.
string $item_id: The source item id.
\Drupal\tmgmt\JobItemInterface The job item that was added to the job or FALSE if it couldn't be saved.
\Drupal\tmgmt\TMGMTException On zero item word count.
Overrides JobInterface::addItem
public function addItem($plugin, $item_type, $item_id) {
$transaction = \Drupal::database()
->startTransaction();
$is_new = FALSE;
if ($this
->isNew()) {
$this
->save();
$is_new = TRUE;
}
$item = tmgmt_job_item_create($plugin, $item_type, $item_id, array(
'tjid' => $this
->id(),
));
$item
->save();
if ($item
->getWordCount() == 0) {
$transaction
->rollback();
// In case we got word count 0 for the first job item, NULL tjid so that
// if there is another addItem() call the rolled back job object will get
// persisted.
if ($is_new) {
$this->tjid = NULL;
}
throw new TMGMTException('Job item @label (@type) has no translatable content.', array(
'@label' => $item
->label(),
'@type' => $item
->getSourceType(),
));
}
return $item;
}