public function LingotekConfigTranslationController::upload in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8 src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 8.2 src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 4.0.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.0.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.1.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.2.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.3.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.4.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.5.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.6.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
- 3.7.x src/Controller/LingotekConfigTranslationController.php \Drupal\lingotek\Controller\LingotekConfigTranslationController::upload()
2 calls to LingotekConfigTranslationController::upload()
1 string reference to 'LingotekConfigTranslationController::upload'
File
- src/
Controller/ LingotekConfigTranslationController.php, line 211
Class
Namespace
Drupal\lingotek\ControllerCode
public function upload($entity_type, $entity_id, Request $request) {
if ($entity_type === $entity_id) {
// It is not a config entity, but a config object.
$definition = $this->configMapperManager
->getDefinition($entity_type);
$mappers = $this->configMapperManager
->getMappers();
if ($this->translationService
->getConfigDocumentId($mappers[$entity_type])) {
try {
if ($this->translationService
->updateConfig($entity_type)) {
$this
->messenger()
->addStatus($this
->t('%label has been updated.', [
'%label' => $definition['title'],
]));
}
} catch (LingotekDocumentNotFoundException $exception) {
$this
->messenger()
->addError($this
->t('Document %label was not found. Please upload again.', [
'%label' => $definition['title'],
]));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addWarning($this
->t('Document %label has been archived. Uploading again.', [
'%label' => $definition['title'],
]));
return $this
->upload($entity_type, $entity_id, $request);
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError($this
->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
'%label' => $definition['title'],
]));
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError($this
->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('%label update failed. Please try again.', [
'%label' => $mappers[$entity_type]
->getTitle(),
]));
}
}
else {
try {
if ($this->translationService
->uploadConfig($entity_type)) {
$this
->messenger()
->addStatus($this
->t('%label uploaded successfully', [
'%label' => $definition['title'],
]));
}
} catch (LingotekDocumentNotFoundException $exception) {
$this
->messenger()
->addError($this
->t('Document %label was not found. Please upload again.', [
'%label' => $mappers[$entity_type]
->getTitle(),
]));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addWarning($this
->t('Document %label has been archived. Uploading again.', [
'%label' => $mappers[$entity_type]
->getTitle(),
]));
return $this
->upload($entity_type, $entity_id, $request);
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError($this
->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
'%label' => $mappers[$entity_type]
->getTitle(),
]));
} catch (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError($this
->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekApiException $e) {
// Mark the document as failed.
$this
->messenger()
->addError($this
->t('%label upload failed. Please try again.', [
'%label' => $mappers[$entity_type]
->getTitle(),
]));
}
}
return $this
->redirectToConfigTranslateOverview($entity_type);
}
// Check if it's a field.
if (substr($entity_type, -7) == '_fields') {
// Hack for fields, the entity is field config.
$entity_type = 'field_config';
}
$entity = $this
->entityTypeManager()
->getStorage($entity_type)
->load($entity_id);
if ($this->translationService
->getDocumentId($entity)) {
try {
if ($doc_id = $this->translationService
->updateDocument($entity)) {
$this
->messenger()
->addStatus($this
->t('%label has been updated.', [
'%label' => $entity
->label(),
]));
}
} catch (LingotekDocumentNotFoundException $exception) {
$this
->messenger()
->addError($this
->t('Document %label was not found. Please upload again.', [
'%label' => $entity
->label(),
]));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addError($this
->t('Document %label has been archived. Uploading again.', [
'%label' => $entity
->label(),
]));
return $this
->upload($entity_type, $entity_id, $request);
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError($this
->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 (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError($this
->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('%label update failed. Please try again.', [
'%label' => $entity
->label(),
]));
}
}
else {
try {
if ($doc_id = $this->translationService
->uploadDocument($entity)) {
$this
->messenger()
->addStatus($this
->t('%label uploaded successfully', [
'%label' => $entity
->label(),
]));
}
} catch (LingotekDocumentNotFoundException $exception) {
$this
->messenger()
->addError($this
->t('Document @entity_type %title was not found. Please upload again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
} catch (LingotekDocumentArchivedException $exception) {
$this
->messenger()
->addWarning($this
->t('Document @entity_type %title has been archived. Uploading again.', [
'@entity_type' => $entity
->getEntityTypeId(),
'%title' => $entity
->label(),
]));
return $this
->upload($entity_type, $entity_id, $request);
} catch (LingotekDocumentLockedException $exception) {
$this
->messenger()
->addError($this
->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 (LingotekPaymentRequiredException $exception) {
$this
->messenger()
->addError($this
->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
} catch (LingotekApiException $e) {
$this
->messenger()
->addError($this
->t('%label upload failed. Please try again.', [
'%label' => $entity
->label(),
]));
}
}
return $this
->redirectToEntityTranslateOverview($entity_type, $entity_id);
}