public function TestSource::saveTranslation in Translation Management Tool 8
Saves a translation.
Parameters
\Drupal\tmgmt\JobItemInterface $job_item: The job item entity.
string $target_langcode: The target language code.
Return value
bool TRUE if the translation was saved successfully, FALSE otherwise.
Overrides SourcePluginInterface::saveTranslation
File
- tmgmt_test/
src/ Plugin/ tmgmt/ Source/ TestSource.php, line 101
Class
- TestSource
- Test source plugin implementation.
Namespace
Drupal\tmgmt_test\Plugin\tmgmt\SourceCode
public function saveTranslation(JobItemInterface $job_item, $target_langcode) {
// Set a variable that can be checked later for a given job item.
$data = $job_item
->getData();
if (isset($data['dummy']['deep_nesting']['#translation']['#text']) && $data['dummy']['deep_nesting']['#translation']['#text'] == 'Invalid translation that will cause an exception') {
throw new \Exception('The translation cannot be saved.');
}
\Drupal::state()
->set('tmgmt_test_saved_translation_' . $job_item
->getItemType() . '_' . $job_item
->getItemId(), $job_item
->getData());
return TRUE;
}