public function LingotekApi::cancelDocumentTarget in Lingotek Translation 3.1.x
Same name and namespace in other branches
- 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
- 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::cancelDocumentTarget()
Cancels the document target with this document id and locale from the Lingotek service.
Parameters
string $document_id: The document id.
string $locale: The locale target we want to cancel the translation.
Return value
\Psr\Http\Message\ResponseInterface A response.
Overrides LingotekApiInterface::cancelDocumentTarget
File
- src/
Remote/ LingotekApi.php, line 157
Class
- LingotekApi
- A simple connector to the Lingotek Translation API.
Namespace
Drupal\lingotek\RemoteCode
public function cancelDocumentTarget($document_id, $locale) {
try {
$this->logger
->debug('Lingotek::cancelDocumentTarget called with id ' . $document_id . ' and locale ' . $locale);
$args = [
'id' => $document_id,
'locale' => $locale,
'cancelled_reason' => 'CANCELLED_BY_AUTHOR',
'mark_invoiceable' => 'true',
];
$response = $this->lingotekClient
->post('/api/document/' . $document_id . '/translation/' . $locale . '/cancel', $args);
} catch (\Exception $e) {
$http_status_code = $e
->getCode();
if ($http_status_code === Response::HTTP_NOT_FOUND) {
$this->logger
->error('Error cancelling document target: %message.', [
'%message' => $e
->getMessage(),
]);
return new Response($e
->getMessage(), Response::HTTP_NOT_FOUND);
}
$this->logger
->error('Error cancelling document target: %message.', [
'%message' => $e
->getMessage(),
]);
throw new LingotekApiException('Failed to cancel document target: ' . $e
->getMessage(), $http_status_code, $e);
}
$this->logger
->debug('cancelDocumentTarget response received, code %code and body %body', [
'%code' => $response
->getStatusCode(),
'%body' => (string) $response
->getBody(TRUE),
]);
return $response;
}