public function TranslationJobToUrl::convert in TMGMT Translator Smartling 8.2
Same name and namespace in other branches
- 8.4 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl::convert()
- 8 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl::convert()
- 8.3 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl::convert()
Converts TMGMTJobItem into Url where that item can be found on the page.
translation job item
Return value
string
File
- src/
Context/ TranslationJobToUrl.php, line 21
Class
Namespace
Drupal\tmgmt_smartling\ContextCode
public function convert(JobItem $job_item) {
if (!$job_item
->hasTranslator() || !$job_item
->getTranslator()
->getPlugin() instanceof SmartlingTranslator) {
return '';
}
try {
$entity_type = $job_item
->getItemType();
$id = $job_item
->getItemId();
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($id);
if (isset($entity->smartling_context_url) && !empty($entity->smartling_context_url)) {
$url = $entity->smartling_context_url;
}
else {
$url = $job_item
->getSourceUrl()
->setAbsolute()
->toString();
}
} catch (\Exception $e) {
$url = '';
}
return $url;
}