public function LingotekConfigManagementForm::uploadDocument in Lingotek Translation 8.2
Same name and namespace in other branches
- 8 src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 4.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.0.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.1.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.2.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.3.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.4.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.5.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.6.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.7.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
- 3.8.x src/Form/LingotekConfigManagementForm.php \Drupal\lingotek\Form\LingotekConfigManagementForm::uploadDocument()
Upload source for translation.
Parameters
\Drupal\config_translation\ConfigMapperInterface $mapper: The mapper.
File
- src/
Form/ LingotekConfigManagementForm.php, line 796
Class
- LingotekConfigManagementForm
- Form for bulk management of content.
Namespace
Drupal\lingotek\FormCode
public function uploadDocument(ConfigMapperInterface $mapper, $language, $job_id, &$context) {
$context['message'] = $this
->t('Uploading %label.', [
'%label' => $mapper
->getTitle(),
]);
/** @var \Drupal\Core\Config\ConfigEntityInterface $entity */
$entity = $mapper instanceof ConfigEntityMapper ? $mapper
->getEntity() : NULL;
$profile = $mapper instanceof ConfigEntityMapper ? $this->lingotekConfiguration
->getConfigEntityProfile($entity) : $this->lingotekConfiguration
->getConfigProfile($mapper
->getPluginId(), FALSE);
$document_id = $mapper instanceof ConfigEntityMapper ? $this->translationService
->getDocumentId($entity) : $this->translationService
->getConfigDocumentId($mapper);
// 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
->uploadDocument($entity, $job_id);
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has been archived. Please upload again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError(t('Document @entity_type %title has a new version. The document id has been updated for all future interactions. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekApiException $e) {
if ($document_id) {
$this
->messenger()
->addError($this
->t('%label update failed. Please try again.', [
'%label' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addError($this
->t('%label upload failed. Please try again.', [
'%label' => $entity
->label(),
]));
}
}
}
else {
try {
$this->translationService
->uploadConfig($mapper
->getPluginId(), $job_id);
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError(t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError(t('Document %label has been archived. Please upload again.', [
'%label' => $mapper
->getTitle(),
]));
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError(t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
'%label' => $mapper
->getTitle(),
]));
} catch (LingotekApiException $e) {
if ($document_id) {
$this
->messenger()
->addError($this
->t('%label update failed. Please try again.', [
'%label' => $mapper
->getTitle(),
]));
}
else {
$this
->messenger()
->addError($this
->t('%label upload failed. Please try again.', [
'%label' => $mapper
->getTitle(),
]));
}
}
}
}
else {
$this
->messenger()
->addWarning($this
->t('%label has no profile assigned so it was not processed.', [
'%label' => $mapper
->getTitle(),
]));
}
}