You are here

public function TranslationJobToUrl::convert in TMGMT Translator Smartling 8

Same name and namespace in other branches
  1. 8.4 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl::convert()
  2. 8.2 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl::convert()
  3. 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

TranslationJobToUrl

Namespace

Drupal\tmgmt_smartling\Context

Code

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;
}