public function LingotekContentTranslationService::cancelDocumentTarget in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8.2 src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 4.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.0.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.1.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.2.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.3.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.4.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.5.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.6.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
- 3.7.x src/LingotekContentTranslationService.php \Drupal\lingotek\LingotekContentTranslationService::cancelDocumentTarget()
Cancels a translation for a given entity in the given locale.
Parameters
\Drupal\Core\Entity\ContentEntityInterface &$entity: The entity which target we want to cancel.
string $locale: Lingotek translation language which we want to modify.
Throws
\Drupal\lingotek\Exception\LingotekDocumentNotFoundException
\Drupal\lingotek\Exception\LingotekApiException
\Drupal\lingotek\Exception\LingotekDocumentTargetAlreadyCompletedException
Overrides LingotekContentTranslationServiceInterface::cancelDocumentTarget
File
- src/
LingotekContentTranslationService.php, line 1615
Class
- LingotekContentTranslationService
- Service for managing Lingotek content translations.
Namespace
Drupal\lingotekCode
public function cancelDocumentTarget(ContentEntityInterface &$entity, $locale) {
$profile = $this->lingotekConfiguration
->getEntityProfile($entity);
if ($profile
->id() === Lingotek::PROFILE_DISABLED || $this
->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED) {
return FALSE;
}
$source_langcode = $entity
->getUntranslated()
->language()
->getId();
$source_locale = $this->languageLocaleMapper
->getLocaleForLangcode($source_langcode);
if ($locale == $source_locale) {
// This is not a target, but the source language itself.
return FALSE;
}
if ($document_id = $this
->getDocumentId($entity)) {
$drupal_language = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale);
try {
if ($this->lingotek
->cancelDocumentTarget($document_id, $locale)) {
$this
->setTargetStatus($entity, $drupal_language
->id(), Lingotek::STATUS_CANCELLED);
return TRUE;
}
} catch (LingotekDocumentNotFoundException $exception) {
$this
->setDocumentId($entity, NULL);
$this
->deleteMetadata($entity);
throw $exception;
}
}
if ($this
->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
$this
->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
}
return FALSE;
}