public function TMGMTEntitySourcePluginController::saveTranslation in Translation Management Tool 7
Saves a translation.
Parameters
TMGMTJobItem $job_item: The job item entity.
Return value
boolean TRUE if the translation was saved successfully, FALSE otherwise.
Overrides TMGMTSourcePluginControllerInterface::saveTranslation
File
- sources/
entity/ tmgmt_entity.plugin.inc, line 42 - Provides the Entity source controller.
Class
- TMGMTEntitySourcePluginController
- @file Provides the Entity source controller.
Code
public function saveTranslation(TMGMTJobItem $job_item) {
$entity = entity_load_single($job_item->item_type, $job_item->item_id);
$job = tmgmt_job_load($job_item->tjid);
tmgmt_field_populate_entity($job_item->item_type, $entity, $job->target_language, $job_item
->getData());
// Change the active language of the entity to the target language.
$handler = entity_translation_get_handler($job_item->item_type, $entity);
$handler
->setFormLanguage($job_item
->getJob()->target_language);
entity_save($job_item->item_type, $entity);
$translation = array(
// @todo Improve hardcoded values.
'translate' => 0,
'status' => TRUE,
'language' => $job_item
->getJob()->target_language,
'source' => $job_item
->getJob()->source_language,
);
$handler
->setTranslation($translation);
$handler
->saveTranslations();
$job_item
->accepted();
}