public function Job::addTranslatedData in Translation Management Tool 8
Store translated data back into the items.
Parameters
array $data: Partially or complete translated data, the most upper key needs to be the translation job item id.
array|string $key: (Optional) Either a flattened key (a 'key1][key2][key3' string) or a nested one, e.g. array('key1', 'key2', 'key2'). Defaults to an empty array which means that it will replace the whole translated data array. The most upper key entry needs to be the job id (tjiid).
int|null $status: (Optional) The data item status that will be set. Defaults to NULL, which means that it will be set to translated unless it was previously set to preliminary, then it will keep that state. Explicitly pass TMGMT_DATA_ITEM_STATE_TRANSLATED or TMGMT_DATA_ITEM_STATE_PRELIMINARY to set it to that value. Other statuses are not supported.
Throws
\Drupal\tmgmt\TMGMTException If is given an unsupported status.
Overrides JobInterface::addTranslatedData
File
- src/
Entity/ Job.php, line 871
Class
- Job
- Entity class for the tmgmt_job entity.
Namespace
Drupal\tmgmt\EntityCode
public function addTranslatedData(array $data, $key = NULL, $status = NULL) {
$key = \Drupal::service('tmgmt.data')
->ensureArrayKey($key);
$items = $this
->getItems();
// If there is a key, get the specific item and forward the call.
if (!empty($key)) {
$item_id = array_shift($key);
if (isset($items[$item_id])) {
$items[$item_id]
->addTranslatedData($data, $key, $status);
}
}
else {
foreach ($data as $key => $value) {
if (isset($items[$key])) {
$items[$key]
->addTranslatedData($value, [], $status);
}
}
}
}