class TranslationJobToUrl in TMGMT Translator Smartling 8.4
Same name and namespace in other branches
- 8 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
- 8.2 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
- 8.3 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
Hierarchy
- class \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
Expanded class hierarchy of TranslationJobToUrl
1 file declares its use of TranslationJobToUrl
- RequestTranslationSubscriber.php in src/
EventSubscriber/ RequestTranslationSubscriber.php
1 string reference to 'TranslationJobToUrl'
1 service uses TranslationJobToUrl
File
- src/
Context/ TranslationJobToUrl.php, line 8
Namespace
Drupal\tmgmt_smartling\ContextView source
class TranslationJobToUrl {
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* Converts TMGMTJobItem into Url where that item can be found on the page.
*
* @var JobItem $job_item
* translation job item
* @return string
*/
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 {
$source_url = $job_item
->getSourceUrl();
$url = empty($source_url) ? '' : $source_url
->setAbsolute()
->toString();
}
} catch (\Exception $e) {
$url = '';
}
return $url;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TranslationJobToUrl:: |
public | function | Converts TMGMTJobItem into Url where that item can be found on the page. | |
TranslationJobToUrl:: |
public | function |