You are here

public function ContentEntitySource::getUrl in Translation Management Tool 8

Returns the Uri for this job item.

Parameters

\Drupal\tmgmt\JobItemInterface $job_item: The job item entity.

Return value

\Drupal\Core\Url|null The URL object for the source object.

Overrides SourcePluginBase::getUrl

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 139

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function getUrl(JobItemInterface $job_item) {

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $langcode = $job_item
    ->getJob() ? $job_item
    ->getJob()
    ->getSourceLangcode() : NULL;
  if ($entity = static::load($job_item
    ->getItemType(), $job_item
    ->getItemId(), $langcode)) {
    if ($entity
      ->hasLinkTemplate('canonical')) {
      $anonymous = new AnonymousUserSession();
      $url = $entity
        ->toUrl();
      $anonymous_access = \Drupal::config('tmgmt.settings')
        ->get('anonymous_access');
      if ($url && $anonymous_access && !$entity
        ->access('view', $anonymous)) {
        $url
          ->setOption('query', [
          'key' => \Drupal::service('tmgmt_content.key_access')
            ->getKey($job_item),
        ]);
      }
      return $url;
    }
  }
  return NULL;
}