You are here

public function TMGMTJob::addItem in Translation Management Tool 7

Adds an item to the translation job.

Parameters

$plugin: The plugin name.

$item_type: The source item type.

$item_id: The source item id.

Return value

TMGMTJobItem The job item that was added to the job or FALSE if it couldn't be saved.

Throws

TMGMTException On zero item word count.

File

entity/tmgmt.entity.job.inc, line 192

Class

TMGMTJob
Entity class for the tmgmt_job entity.

Code

public function addItem($plugin, $item_type, $item_id) {
  $transaction = db_transaction();
  $is_new = FALSE;
  if (empty($this->tjid)) {
    $this
      ->save();
    $is_new = TRUE;
  }
  $item = tmgmt_job_item_create($plugin, $item_type, $item_id, array(
    'tjid' => $this->tjid,
  ));
  $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;
}