You are here

class TranslationJobToUrl in TMGMT Translator Smartling 8

Same name and namespace in other branches
  1. 8.4 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
  2. 8.2 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl
  3. 8.3 src/Context/TranslationJobToUrl.php \Drupal\tmgmt_smartling\Context\TranslationJobToUrl

Hierarchy

Expanded class hierarchy of TranslationJobToUrl

1 file declares its use of TranslationJobToUrl
RequestTranslationSubscriber.php in src/EventSubscriber/RequestTranslationSubscriber.php
1 string reference to 'TranslationJobToUrl'
tmgmt_smartling.services.yml in ./tmgmt_smartling.services.yml
tmgmt_smartling.services.yml
1 service uses TranslationJobToUrl
tmgmt_smartling.utils.context.job_url in ./tmgmt_smartling.services.yml
Drupal\tmgmt_smartling\Context\TranslationJobToUrl

File

src/Context/TranslationJobToUrl.php, line 8

Namespace

Drupal\tmgmt_smartling\Context
View 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 {
        $url = $job_item
          ->getSourceUrl()
          ->setAbsolute()
          ->toString();
      }
    } catch (\Exception $e) {
      $url = '';
    }
    return $url;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TranslationJobToUrl::convert public function Converts TMGMTJobItem into Url where that item can be found on the page.
TranslationJobToUrl::__construct public function