You are here

protected function LingotekTargetTrait::getTargetActionUrl in Lingotek Translation 3.7.x

Same name and namespace in other branches
  1. 4.0.x src/Element/LingotekTargetTrait.php \Drupal\lingotek\Element\LingotekTargetTrait::getTargetActionUrl()
  2. 3.6.x src/Element/LingotekTargetTrait.php \Drupal\lingotek\Element\LingotekTargetTrait::getTargetActionUrl()
  3. 3.8.x src/Element/LingotekTargetTrait.php \Drupal\lingotek\Element\LingotekTargetTrait::getTargetActionUrl()

Get the target action url based on the source status.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.

string $target_status: The target status.

string $langcode: The language code.

Return value

\Drupal\Core\Url An url object.

2 calls to LingotekTargetTrait::getTargetActionUrl()
LingotekTargetStatus::preRender in src/Element/LingotekTargetStatus.php
Calculates the url and status title and adds them to the render array.
LingotekTargetStatuses::getTranslationsStatuses in src/Element/LingotekTargetStatuses.php
Gets the translation status of an entity in a format ready to display.

File

src/Element/LingotekTargetTrait.php, line 28

Class

LingotekTargetTrait
Trait for lingotek_target_status and lingotek_target_statuses reuse.

Namespace

Drupal\lingotek\Element

Code

protected function getTargetActionUrl(ContentEntityInterface &$entity, $target_status, $langcode) {
  $url = NULL;
  $document_id = \Drupal::service('lingotek.content_translation')
    ->getDocumentId($entity);
  $locale = \Drupal::service('lingotek.language_locale_mapper')
    ->getLocaleForLangcode($langcode);
  if ($document_id) {
    if (in_array($target_status, [
      Lingotek::STATUS_REQUEST,
      Lingotek::STATUS_DELETED,
    ])) {
      $url = Url::fromRoute('lingotek.entity.request_translation', [
        'doc_id' => $document_id,
        'locale' => $locale,
      ], [
        'query' => $this
          ->getDestinationWithQueryArray(),
      ]);
    }
    if ($target_status == Lingotek::STATUS_PENDING) {
      $url = Url::fromRoute('lingotek.entity.check_target', [
        'doc_id' => $document_id,
        'locale' => $locale,
      ], [
        'query' => $this
          ->getDestinationWithQueryArray(),
      ]);
    }
    if ($target_status == Lingotek::STATUS_READY || $target_status == Lingotek::STATUS_ERROR) {
      $url = Url::fromRoute('lingotek.entity.download', [
        'doc_id' => $document_id,
        'locale' => $locale,
      ], [
        'query' => $this
          ->getDestinationWithQueryArray(),
      ]);
    }
    if ($target_status == Lingotek::STATUS_CURRENT || $target_status == Lingotek::STATUS_INTERMEDIATE || $target_status == Lingotek::STATUS_EDITED) {
      $url = Url::fromRoute('lingotek.workbench', [
        'doc_id' => $document_id,
        'locale' => $locale,
      ]);
    }
    if ($target_status == Lingotek::STATUS_UNTRACKED) {
      $url = Url::fromRoute('lingotek.entity.request_translation', [
        'doc_id' => $document_id,
        'locale' => $locale,
      ], [
        'query' => $this
          ->getDestinationWithQueryArray(),
      ]);
    }
    if ($target_status == Lingotek::STATUS_DISABLED) {
      $url = NULL;
    }
  }
  return $url;
}