You are here

protected function LingotekConfigManagementForm::getTranslationsStatuses in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  2. 4.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  3. 3.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  4. 3.1.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  5. 3.2.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  6. 3.3.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  7. 3.4.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  8. 3.5.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  9. 3.6.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  10. 3.7.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()
  11. 3.8.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::getTranslationsStatuses()

Gets the translation status of an entity in a format ready to display.

Parameters

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

Return value

array A render array.

1 call to LingotekConfigManagementForm::getTranslationsStatuses()
LingotekConfigManagementForm::buildForm in src/Form/LingotekConfigManagementForm.php
Form constructor.

File

src/Form/LingotekConfigManagementForm.php, line 1079
Contains \Drupal\Lingotek\Form\LingotekConfigManagementForm.

Class

LingotekConfigManagementForm
Form for bulk management of content.

Namespace

Drupal\lingotek\Form

Code

protected function getTranslationsStatuses(ConfigMapperInterface &$mapper) {
  $is_config_entity = $mapper instanceof ConfigEntityMapper;
  $translations = [];
  $languages = $this->languageManager
    ->getLanguages();
  $languages = array_filter($languages, function (LanguageInterface $language) {
    $configLanguage = ConfigurableLanguage::load($language
      ->getId());
    return $this->lingotekConfiguration
      ->isLanguageEnabled($configLanguage);
  });
  $document_id = $is_config_entity ? $this->translationService
    ->getDocumentId($mapper
    ->getEntity()) : $this->translationService
    ->getConfigDocumentId($mapper);
  $entity = $is_config_entity ? $mapper
    ->getEntity() : NULL;
  if ($document_id) {
    $translations_statuses = $mapper instanceof ConfigEntityMapper ? $this->translationService
      ->getTargetStatuses($entity) : $this->translationService
      ->getConfigTargetStatuses($mapper);
    foreach ($translations_statuses as $langcode => $status) {
      if (isset($languages[$langcode]) && $langcode !== $mapper
        ->getLangcode() && key_exists($langcode, $languages)) {
        if ($mapper
          ->hasTranslation($languages[$langcode]) && $status == Lingotek::STATUS_REQUEST) {
          $translations[$langcode] = [
            'status' => Lingotek::STATUS_UNTRACKED,
            'url' => $this
              ->getTargetActionUrl($mapper, Lingotek::STATUS_UNTRACKED, $langcode),
            'new_window' => $status == Lingotek::STATUS_CURRENT,
          ];
        }
        else {
          $translations[$langcode] = [
            'status' => $status,
            'url' => $this
              ->getTargetActionUrl($mapper, $status, $langcode),
            'new_window' => $status == Lingotek::STATUS_CURRENT,
          ];
        }
      }
    }
    array_walk($languages, function ($language, $langcode) use ($mapper, &$translations) {
      if (!isset($translations[$langcode]) && $langcode !== $mapper
        ->getLangcode()) {
        $translations[$langcode] = [
          'status' => Lingotek::STATUS_REQUEST,
          'url' => $this
            ->getTargetActionUrl($mapper, Lingotek::STATUS_REQUEST, $langcode),
          'new_window' => false,
        ];
      }
    });
  }
  else {
    foreach ($languages as $langcode => $language) {

      // Show the untracked translations in the bulk management form, unless it's the
      // source one.
      if ($mapper
        ->hasTranslation($language) && $mapper
        ->getLangcode() !== $langcode) {
        $translations[$langcode] = [
          'status' => Lingotek::STATUS_UNTRACKED,
          'url' => NULL,
          'new_window' => false,
        ];
      }
    }
  }
  ksort($translations);
  return $this
    ->formatTranslations($mapper, $translations);
}