public function LingotekConfigTranslationService::addTarget in Lingotek Translation 3.7.x
Same name and namespace in other branches
- 8 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 8.2 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 4.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.1.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.2.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.3.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.4.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.5.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.6.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
- 3.8.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addTarget()
Request a translation for a given entity in the given locale.
Parameters
\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The entity which target we want to add.
string $locale: Lingotek translation language which we want to modify.
Throws
\Drupal\lingotek\Exception\LingotekPaymentRequiredException
\Drupal\lingotek\Exception\LingotekDocumentArchivedException
\Drupal\lingotek\Exception\LingotekDocumentLockedException
\Drupal\lingotek\Exception\LingotekDocumentNotFoundException
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekConfigTranslationServiceInterface::addTarget
File
- src/
LingotekConfigTranslationService.php, line 573
Class
- LingotekConfigTranslationService
- Service for managing Lingotek configuration translations.
Namespace
Drupal\lingotekCode
public function addTarget(ConfigEntityInterface &$entity, $locale) {
$profile = $this->lingotekConfiguration
->getConfigEntityProfile($entity);
$drupal_language = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale);
if ($profile
->id() === Lingotek::PROFILE_DISABLED || $this
->getSourceStatus($entity) === Lingotek::STATUS_CANCELLED || $profile
->hasDisabledTarget($drupal_language
->getId())) {
return FALSE;
}
if ($locale == $this->languageLocaleMapper
->getLocaleForLangcode($entity
->language()
->getId())) {
// We don't want to translate from one language to itself.
return FALSE;
}
if ($document_id = $this
->getDocumentId($entity)) {
$source_status = $this
->getSourceStatus($entity);
$current_status = $this
->getTargetStatus($entity, $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale)
->getId());
if ($current_status !== Lingotek::STATUS_PENDING && $current_status !== Lingotek::STATUS_CURRENT && $current_status !== Lingotek::STATUS_READY) {
try {
$result = $this->lingotek
->addTarget($document_id, $locale, $this->lingotekConfiguration
->getConfigEntityProfile($entity));
} catch (LingotekDocumentNotFoundException $exception) {
$this
->setDocumentId($entity, NULL);
$this
->deleteMetadata($entity);
throw $exception;
} catch (LingotekDocumentLockedException $exception) {
$this
->setDocumentId($entity, $exception
->getNewDocumentId());
throw $exception;
} catch (LingotekDocumentArchivedException $exception) {
$this
->setDocumentId($entity, NULL);
$this
->deleteMetadata($entity);
throw $exception;
} catch (LingotekPaymentRequiredException $exception) {
throw $exception;
} catch (LingotekApiException $exception) {
throw $exception;
}
if ($result) {
$this
->setTargetStatus($entity, $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale)
->getId(), Lingotek::STATUS_PENDING);
// If the status was "Importing", and the target was added
// successfully, we can ensure that the content is current now.
if ($source_status == Lingotek::STATUS_IMPORTING) {
$this
->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
}
return TRUE;
}
}
}
if ($this
->getSourceStatus($entity) == Lingotek::STATUS_DISABLED) {
$this
->setTargetStatuses($entity, Lingotek::STATUS_DISABLED);
}
return FALSE;
}