public function LingotekManagementFormBase::uploadDocument in Lingotek Translation 3.4.x
Same name and namespace in other branches
- 8.2 src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 4.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.0.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.1.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.2.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.3.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.5.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.6.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.7.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
- 3.8.x src/Form/LingotekManagementFormBase.php \Drupal\lingotek\Form\LingotekManagementFormBase::uploadDocument()
Upload source for translation.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity.
File
- src/
Form/ LingotekManagementFormBase.php, line 1076
Class
- LingotekManagementFormBase
- Form for bulk management of content.
Namespace
Drupal\lingotek\FormCode
public function uploadDocument(ContentEntityInterface $entity, $language, $job_id, &$context) {
$context['message'] = $this
->t('Uploading @type %label.', [
'@type' => $entity
->getEntityType()
->getLabel(),
'%label' => $entity
->label(),
]);
$bundleInfos = $this->entityTypeBundleInfo
->getBundleInfo($entity
->getEntityTypeId());
if (!$entity
->getEntityType()
->isTranslatable() || !$bundleInfos[$entity
->bundle()]['translatable']) {
\Drupal::messenger()
->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for translation.', [
'@type' => $bundleInfos[$entity
->bundle()]['label'],
'%label' => $entity
->label(),
'@bundle_label' => $entity
->getEntityType()
->getBundleLabel(),
]));
return;
}
if (!$this->lingotekConfiguration
->isEnabled($entity
->getEntityTypeId(), $entity
->bundle())) {
$this
->messenger()
->addWarning(t('Cannot upload @type %label. That @bundle_label is not enabled for Lingotek translation.', [
'@type' => $bundleInfos[$entity
->bundle()]['label'],
'%label' => $entity
->label(),
'@bundle_label' => $entity
->getEntityType()
->getBundleLabel(),
]));
return;
}
if ($profile = $this->lingotekConfiguration
->getEntityProfile($entity)) {
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 $exception) {
if ($this->translationService
->getDocumentId($entity)) {
$this
->messenger()
->addError(t('The update for @entity_type %title failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
else {
$this
->messenger()
->addError(t('The upload for @entity_type %title failed. Please try again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
}
}
}
else {
$bundleInfos = $this->entityTypeBundleInfo
->getBundleInfo($entity
->getEntityTypeId());
$this
->messenger()
->addWarning($this
->t('The @type %label has no profile assigned so it was not processed.', [
'@type' => $bundleInfos[$entity
->bundle()]['label'],
'%label' => $entity
->label(),
]));
}
}