protected function LingotekManagementForm::getTranslationsStatuses in Lingotek Translation 8
Gets the translation status of an entity in a format ready to display.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.
Return value
array A render array.
1 call to LingotekManagementForm::getTranslationsStatuses()
- LingotekManagementForm::buildForm in src/
Form/ LingotekManagementForm.php - Form constructor.
File
- src/
Form/ LingotekManagementForm.php, line 1050 - Contains \Drupal\Lingotek\Form\LingotekManagementForm.
Class
- LingotekManagementForm
- Form for bulk management of content.
Namespace
Drupal\lingotek\FormCode
protected function getTranslationsStatuses(ContentEntityInterface &$entity) {
$translations = [];
$languages = $this->languageManager
->getLanguages();
$languages = array_filter($languages, function (LanguageInterface $language) {
$configLanguage = ConfigurableLanguage::load($language
->getId());
return $this->lingotekConfiguration
->isLanguageEnabled($configLanguage);
});
$document_id = $this->translationService
->getDocumentId($entity);
if ($entity->lingotek_translation_status && $document_id) {
foreach ($entity->lingotek_translation_status
->getIterator() as $delta => $field_value) {
if ($field_value->language !== $entity
->language()
->getId() && key_exists($field_value->language, $languages)) {
// We may have an existing translation already.
if ($entity
->hasTranslation($field_value->language) && $field_value->value == Lingotek::STATUS_REQUEST) {
$translations[$field_value->language] = [
'status' => Lingotek::STATUS_UNTRACKED,
'url' => $this
->getTargetActionUrl($entity, Lingotek::STATUS_UNTRACKED, $field_value->language),
'new_window' => FALSE,
];
}
else {
$translations[$field_value->language] = [
'status' => $field_value->value,
'url' => $this
->getTargetActionUrl($entity, $field_value->value, $field_value->language),
'new_window' => $field_value->value == Lingotek::STATUS_CURRENT,
];
}
}
}
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,
];
}
});
}
else {
foreach ($languages as $langcode => $language) {
// Show the untracked translations in the bulk management form, unless it's the
// source one.
if ($entity
->hasTranslation($langcode) && $entity
->getUntranslated()
->language()
->getId() !== $langcode) {
$translations[$langcode] = [
'status' => Lingotek::STATUS_UNTRACKED,
'url' => NULL,
'new_window' => false,
];
}
}
}
ksort($translations);
return $this
->formatTranslations($entity, $translations);
}