protected function LingotekTargetStatuses::getTranslationsStatuses in Lingotek Translation 8.2
Same name and namespace in other branches
- 4.0.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.0.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.1.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.2.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.3.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.4.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.5.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.6.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.7.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
- 3.8.x src/Element/LingotekTargetStatuses.php \Drupal\lingotek\Element\LingotekTargetStatuses::getTranslationsStatuses()
Gets the translation status of an entity in a format ready to display.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.
string $source_langcode: The source language code.
array $statuses: Array of known statuses keyed by language code.
Return value
array A render array.
1 call to LingotekTargetStatuses::getTranslationsStatuses()
- 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 67
Class
- LingotekTargetStatuses
- Provides a Lingotek target status element.
Namespace
Drupal\lingotek\ElementCode
protected function getTranslationsStatuses(ContentEntityInterface &$entity, $source_langcode, array $statuses) {
$translations = [];
$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 ($entity
->hasTranslation($langcode) && $status == Lingotek::STATUS_REQUEST) {
$translations[$langcode] = [
'status' => Lingotek::STATUS_UNTRACKED,
'url' => $this
->getTargetActionUrl($entity, Lingotek::STATUS_UNTRACKED, $langcode),
'new_window' => FALSE,
];
}
else {
$translations[$langcode] = [
'status' => $status,
'url' => $this
->getTargetActionUrl($entity, $status, $langcode),
'new_window' => in_array($status, [
Lingotek::STATUS_CURRENT,
Lingotek::STATUS_INTERMEDIATE,
Lingotek::STATUS_EDITED,
]),
];
}
}
array_walk($languages, function ($language, $langcode) use ($entity, &$translations) {
if (!isset($translations[$langcode]) && $langcode !== $entity
->getUntranslated()
->language()
->getId()) {
$translations[$langcode] = [
'status' => Lingotek::STATUS_REQUEST,
'url' => $this
->getTargetActionUrl($entity, 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]) && $entity
->hasTranslation($langcode) && $source_langcode !== $langcode) {
$translations[$langcode] = [
'status' => Lingotek::STATUS_UNTRACKED,
'url' => NULL,
'new_window' => FALSE,
];
}
}
ksort($translations);
foreach ($translations as $langcode => &$translation) {
$translation['status_text'] = $this
->getTargetStatusText($entity, $translation['status'], $langcode);
$translation['language'] = $langcode;
}
return $translations;
}