public function LingotekConfigTranslationService::addConfigTarget in Lingotek Translation 3.3.x
Same name and namespace in other branches
- 8 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 8.2 src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 4.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.0.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.1.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.2.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.4.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.5.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.6.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.7.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
- 3.8.x src/LingotekConfigTranslationService.php \Drupal\lingotek\LingotekConfigTranslationService::addConfigTarget()
Request a translation for a given entity in the given locale.
Parameters
string $mapper_id: 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\LingotekApiException
Overrides LingotekConfigTranslationServiceInterface::addConfigTarget
File
- src/
LingotekConfigTranslationService.php, line 1142
Class
- LingotekConfigTranslationService
- Service for managing Lingotek configuration translations.
Namespace
Drupal\lingotekCode
public function addConfigTarget($mapper_id, $locale) {
$mapper = $this->mappers[$mapper_id];
$profile = $this->lingotekConfiguration
->getConfigProfile($mapper_id);
if ($profile
->id() === Lingotek::PROFILE_DISABLED || $this
->getConfigSourceStatus($mapper) === Lingotek::STATUS_CANCELLED) {
return FALSE;
}
if ($locale == $this->languageLocaleMapper
->getLocaleForLangcode($mapper
->getLangcode())) {
// We don't want to translate from one language to itself.
return FALSE;
}
if ($document_id = $this
->getConfigDocumentId($mapper)) {
$source_status = $this
->getConfigSourceStatus($mapper);
$current_status = $this
->getConfigTargetStatus($mapper, $locale);
if ($current_status !== Lingotek::STATUS_PENDING && $current_status !== Lingotek::STATUS_CURRENT && $current_status !== Lingotek::STATUS_READY) {
try {
$result = $this->lingotek
->addTarget($document_id, $locale);
} catch (LingotekDocumentLockedException $exception) {
$this
->setConfigDocumentId($mapper, $exception
->getNewDocumentId());
throw $exception;
} catch (LingotekDocumentArchivedException $exception) {
$this
->setConfigDocumentId($mapper, NULL);
$this
->deleteConfigMetadata($mapper_id);
throw $exception;
} catch (LingotekPaymentRequiredException $exception) {
throw $exception;
} catch (LingotekApiException $exception) {
throw $exception;
}
if ($result) {
$this
->setConfigTargetStatus($mapper, $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
->setConfigSourceStatus($mapper, Lingotek::STATUS_CURRENT);
}
return TRUE;
}
}
}
if ($this
->getConfigSourceStatus($mapper) == Lingotek::STATUS_DISABLED) {
$this
->setConfigTargetStatuses($mapper, Lingotek::STATUS_DISABLED);
}
return FALSE;
}