public function LingotekConfigManagementForm::cancelTarget in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8.2 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.1.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.2.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.3.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.4.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.5.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.6.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.7.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
- 3.8.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::cancelTarget()
Cancel the content from Lingotek.
Parameters
\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.
File
- src/
Form/ LingotekConfigManagementForm.php, line 1290
Class
- LingotekConfigManagementForm
- Form for bulk management of content.
Namespace
Drupal\lingotek\FormCode
public function cancelTarget(ConfigMapperInterface $mapper, $langcode, $job_id, &$context) {
$context['message'] = $this
->t('Cancelling translation for %label to language @language.', [
'%label' => $mapper
->getTitle(),
'@language' => $langcode,
]);
$locale = $this->languageLocaleMapper
->getLocaleForLangcode($langcode);
$entity = $mapper instanceof ConfigEntityMapper ? $mapper
->getEntity() : NULL;
$profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
->getConfigEntityProfile($entity, FALSE) : $this->lingotekConfiguration
->getConfigProfile($mapper
->getPluginId(), FALSE);
// If there is no entity, it's a config object and we don't abort based on
// the profile.
if ($entity === NULL || $profile !== NULL) {
if ($mapper instanceof ConfigEntityMapper) {
try {
$this->translationService
->cancelDocumentTarget($entity, $locale);
} catch (LingotekDocumentTargetAlreadyCompletedException $e) {
$this->translationService
->checkTargetStatus($entity, $locale);
$this
->messenger()
->addError($this
->t('Target %language for %label was already completed in the TMS and cannot be cancelled unless the entire document is cancelled.', [
'%label' => $entity
->label(),
'%language' => $langcode,
]));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('Cancelling translation for %label to language @language failed. Please try again.', [
'%label' => $entity
->label(),
'@language' => $langcode,
]));
}
}
else {
try {
$this->translationService
->cancelConfigDocumentTarget($mapper
->getPluginId(), $locale);
} catch (LingotekDocumentTargetAlreadyCompletedException $e) {
$this->translationService
->checkConfigTargetStatus($mapper, $locale);
$this
->messenger()
->addError($this
->t('Target %language for %label was already completed in the TMS and cannot be cancelled unless the entire document is cancelled.', [
'%label' => $mapper
->getTitle(),
'%language' => $langcode,
]));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('Cancelling translation for %label to language @language failed. Please try again.', [
'%label' => $mapper
->getTitle(),
'@language' => $langcode,
]));
}
}
}
elseif ($profile = $this->lingotekConfiguration
->getConfigProfile($mapper
->getPluginId(), FALSE) or TRUE) {
try {
$this->translationService
->cancelConfigDocumentTarget($mapper
->getPluginId());
} catch (LingotekDocumentTargetAlreadyCompletedException $e) {
$this->translationService
->checkConfigTargetStatus($mapper, $locale);
$this
->messenger()
->addError($this
->t('Target %language for %label was already completed in the TMS and cannot be cancelled unless the entire document is cancelled.', [
'%label' => $mapper
->getTitle(),
'%language' => $langcode,
]));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('Cancelling translation for %label to language @language. Please try again.', [
'%label' => $mapper
->getTitle(),
'@language' => $langcode,
]));
}
}
else {
$this
->messenger()
->addWarning($this
->t('%label has no profile assigned so it was not processed.', [
'%label' => $mapper
->getTitle(),
]));
}
}