You are here

public function JobItem::addRemoteMapping in Translation Management Tool 8

Adds remote mapping entity to this job item.

Parameters

string $data_item_key: Job data item key.

int $remote_identifier_1: Array of remote identifiers. In case you need to save remote_identifier_2/3 set it into $mapping_data argument.

array $mapping_data: Additional data to be added.

Return value

int|bool Returns either the integer or boolean.

Throws

TMGMTException Throws an exception.

Overrides JobItemInterface::addRemoteMapping

File

src/Entity/JobItem.php, line 947

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public function addRemoteMapping($data_item_key = NULL, $remote_identifier_1 = NULL, $mapping_data = array()) {
  if (empty($remote_identifier_1) && !isset($mapping_data['remote_identifier_2']) && !isset($remote_mapping['remote_identifier_3'])) {
    throw new TMGMTException('Cannot create remote mapping without remote identifier.');
  }
  $data = array(
    'tjid' => $this
      ->getJobId(),
    'tjiid' => $this
      ->id(),
    'data_item_key' => $data_item_key,
    'remote_identifier_1' => $remote_identifier_1,
  );
  if (!empty($mapping_data)) {
    $data += $mapping_data;
  }
  $remote_mapping = RemoteMapping::create($data);
  return $remote_mapping
    ->save();
}