You are here

protected function LingotekTargetStatuses::getSecondaryTargetActionUrlsForConfigMapper in Lingotek Translation 3.8.x

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

Get secondary target actions, which will be shown when expanded.

Parameters

\Drupal\config_translation\ConfigMapperInterface $mapper: The entity.

string $target_status: The target status.

string $langcode: The language code.

Return value

array Array of links.

1 call to LingotekTargetStatuses::getSecondaryTargetActionUrlsForConfigMapper()
LingotekTargetStatuses::getTranslationsStatusesForConfigMapper in src/Element/LingotekTargetStatuses.php

File

src/Element/LingotekTargetStatuses.php, line 316

Class

LingotekTargetStatuses
Provides a Lingotek target status element.

Namespace

Drupal\lingotek\Element

Code

protected function getSecondaryTargetActionUrlsForConfigMapper(ConfigMapperInterface &$mapper, $target_status, $langcode) {
  $url = NULL;
  $target_status = strtoupper($target_status);
  $language = \Drupal::languageManager()
    ->getLanguage($langcode);
  $translationService = \Drupal::service('lingotek.config_translation');

  /** @var \Drupal\Core\Config\ConfigEntityInterface $entity */
  $entity = $mapper instanceof ConfigEntityMapper ? $mapper
    ->getEntity() : NULL;
  $document_id = $mapper instanceof ConfigEntityMapper ? $translationService
    ->getDocumentId($entity) : $translationService
    ->getConfigDocumentId($mapper);
  $locale = \Drupal::service('lingotek.language_locale_mapper')
    ->getLocaleForLangcode($language
    ->getId());
  $langcode_upper = strtoupper($langcode);
  $language = \Drupal::languageManager()
    ->getLanguage($langcode);
  $args = $this
    ->getActionUrlArgumentsForConfigMapper($mapper);
  $actions = [];
  if ($document_id) {
    if (in_array($target_status, [
      Lingotek::STATUS_REQUEST,
      Lingotek::STATUS_DELETED,
    ])) {
      $actions[] = [
        'title' => $this
          ->t('Request translation'),
        'url' => Url::fromRoute('lingotek.config.request', $args + [
          'locale' => $locale,
        ], [
          'query' => $this
            ->getDestinationWithQueryArray(),
        ]),
      ];
    }
    if ($target_status == Lingotek::STATUS_PENDING) {
      $actions[] = [
        'title' => $this
          ->t('Check translation status'),
        'url' => Url::fromRoute('lingotek.config.check_download', $args + [
          'locale' => $locale,
        ], [
          'query' => $this
            ->getDestinationWithQueryArray(),
        ]),
        'new_window' => FALSE,
      ];
      $actions[] = [
        'title' => $this
          ->t('Open in Lingotek Workbench'),
        'url' => Url::fromRoute('lingotek.workbench', [
          'doc_id' => $document_id,
          'locale' => $locale,
        ]),
        'new_window' => TRUE,
      ];
    }
    if ($target_status == Lingotek::STATUS_READY) {
      $actions[] = [
        'title' => $this
          ->t('Download translation'),
        'url' => Url::fromRoute('lingotek.config.download', $args + [
          'locale' => $locale,
        ], [
          'query' => $this
            ->getDestinationWithQueryArray(),
        ]),
        'new_window' => FALSE,
      ];
      $actions[] = [
        'title' => $this
          ->t('Open in Lingotek Workbench'),
        'url' => Url::fromRoute('lingotek.workbench', [
          'doc_id' => $document_id,
          'locale' => $locale,
        ]),
        'new_window' => TRUE,
      ];

      // TODO add url for disassociate.
    }
    if ($target_status == Lingotek::STATUS_ERROR) {
      $actions[] = [
        'title' => $this
          ->t('Retry'),
        'url' => Url::fromRoute('lingotek.config.request', $args + [
          'locale' => $locale,
        ], [
          'query' => $this
            ->getDestinationWithQueryArray(),
        ]),
        'new_window' => FALSE,
      ];
    }
    if ($target_status == Lingotek::STATUS_CURRENT) {
      $actions[] = [
        'title' => $this
          ->t('Open in Lingotek Workbench'),
        'url' => Url::fromRoute('lingotek.workbench', [
          'doc_id' => $document_id,
          'locale' => $locale,
        ]),
        'new_window' => TRUE,
      ];
    }
    if ($target_status == Lingotek::STATUS_INTERMEDIATE) {
      $actions[] = [
        'title' => $this
          ->t('Open in Lingotek Workbench'),
        'url' => Url::fromRoute('lingotek.workbench', [
          'doc_id' => $document_id,
          'locale' => $locale,
        ]),
        'new_window' => TRUE,
      ];
    }
    if ($target_status == Lingotek::STATUS_EDITED) {
      $actions[] = [
        'title' => $this
          ->t('Open in Lingotek Workbench'),
        'url' => Url::fromRoute('lingotek.workbench', [
          'doc_id' => $document_id,
          'locale' => $locale,
        ]),
        'new_window' => TRUE,
      ];
    }
  }
  if (in_array($target_status, [
    Lingotek::STATUS_UNTRACKED,
    Lingotek::STATUS_ARCHIVED,
  ])) {
    if ($document_id) {
      $actions[] = [
        'title' => $this
          ->t('Request translation'),
        'url' => Url::fromRoute('lingotek.config.request', $args + [
          'locale' => $locale,
        ], [
          'query' => $this
            ->getDestinationWithQueryArray(),
        ]),
        'new_window' => FALSE,
      ];
    }
  }
  return $actions;
}