You are here

protected function LingotekTargetStatuses::getTranslationsStatusesForConfigMapper in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.6.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatusesForConfigMapper()
  2. 3.7.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatusesForConfigMapper()
  3. 3.8.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatusesForConfigMapper()
1 call to LingotekTargetStatuses::getTranslationsStatusesForConfigMapper()
LingotekTargetStatuses::preRender in src/Element/LingotekTargetStatuses.php
Calculates the url and status title and adds them to the render array.

File

src/Element/LingotekTargetStatuses.php, line 141

Class

LingotekTargetStatuses
Provides a Lingotek target status element.

Namespace

Drupal\lingotek\Element

Code

protected function getTranslationsStatusesForConfigMapper(ConfigMapperInterface &$mapper, $source_langcode, array $statuses) {
  $translations = [];
  foreach ($statuses as $langcode => &$status) {
    $status['actions'] = $this
      ->getSecondaryTargetActionUrlsForConfigMapper($mapper, $status['status'], $status['language']);
  }
  return $statuses;
  $languages = \Drupal::languageManager()
    ->getLanguages();
  $languages = array_filter($languages, function (LanguageInterface $language) {
    $configLanguage = ConfigurableLanguage::load($language
      ->getId());
    return \Drupal::service('lingotek.configuration')
      ->isLanguageEnabled($configLanguage);
  });
  foreach ($statuses as $langcode => $status) {
    if ($langcode !== $source_langcode && array_key_exists($langcode, $languages)) {

      // We may have an existing translation already.
      if ($mapper instanceof ConfigEntityMapper && $mapper
        ->getEntity()
        ->hasTranslation($langcode) && $status == Lingotek::STATUS_REQUEST) {
        $translations[$langcode] = [
          'status' => Lingotek::STATUS_UNTRACKED,
          'url' => $this
            ->getTargetActionUrlForConfigMapper($mapper, Lingotek::STATUS_UNTRACKED, $langcode),
          'actions' => $this
            ->getSecondaryTargetActionUrlsForConfigMapper($mapper, Lingotek::STATUS_UNTRACKED, $langcode),
          'new_window' => FALSE,
        ];
      }
      else {
        $translations[$langcode] = [
          'status' => $status,
          'url' => $this
            ->getTargetActionUrlForConfigMapper($mapper, $status, $langcode),
          'actions' => $this
            ->getSecondaryTargetActionUrlsForConfigMapper($mapper, $status, $langcode),
          'new_window' => in_array($status, [
            Lingotek::STATUS_CURRENT,
            Lingotek::STATUS_INTERMEDIATE,
            Lingotek::STATUS_EDITED,
          ]),
        ];
      }
    }
    array_walk($languages, function ($language, $langcode) use ($mapper, &$translations) {
      if ($mapper instanceof ConfigEntityMapper) {
        if (!isset($translations[$langcode]) && $langcode !== $mapper
          ->getEntity()
          ->getUntranslated()
          ->language()
          ->getId()) {
          $translations[$langcode] = [
            'status' => Lingotek::STATUS_REQUEST,
            'url' => $this
              ->getTargetActionUrlForConfigMapper($mapper, Lingotek::STATUS_REQUEST, $langcode),
            'actions' => $this
              ->getSecondaryTargetActionUrlsForConfigMapper($mapper, Lingotek::STATUS_REQUEST, $langcode),
            'new_window' => FALSE,
          ];
        }
      }
    });
  }
  foreach ($languages as $langcode => $language) {

    // Show the untracked translations in the bulk management form, unless it's the
    // source one.
    if (!isset($translations[$langcode]) && $mapper instanceof ConfigEntityMapper && $mapper
      ->getEntity()
      ->hasTranslation($langcode) && $source_langcode !== $langcode) {
      $translations[$langcode] = [
        'status' => Lingotek::STATUS_UNTRACKED,
        'url' => NULL,
        'actions' => $this
          ->getSecondaryTargetActionUrlsForConfigMapper($mapper, Lingotek::STATUS_UNTRACKED, $langcode),
        'new_window' => FALSE,
      ];
    }
  }
  ksort($translations);
  foreach ($translations as $langcode => &$translation) {
    $hasTranslation = $mapper instanceof ConfigEntityMapper ? $mapper
      ->getEntity()
      ->hasTranslation($langcode) : FALSE;
    $translation['status_text'] = $this
      ->getTargetStatusText($translation['status'], $langcode, $hasTranslation);
    $translation['language'] = $langcode;
  }
  return $translations;
}