public function LingotekApi::getDocumentContent in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.1.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
- 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getDocumentContent()
Gets the document content from Lingotek.
Parameters
string $doc_id: The document id.
Return value
string The content.
Throws
\Drupal\lingotek\Exception\LingotekApiException
Overrides LingotekApiInterface::getDocumentContent
File
- src/
Remote/ LingotekApi.php, line 202
Class
- LingotekApi
- A simple connector to the Lingotek Translation API.
Namespace
Drupal\lingotek\RemoteCode
public function getDocumentContent($doc_id) {
try {
$this->logger
->debug('Lingotek::getDocumentContent called with id %id', [
'%id' => $doc_id,
]);
$response = $this->lingotekClient
->get('/api/document/' . $doc_id . '/content');
} catch (ClientException $e) {
if ($e
->getCode() === Response::HTTP_NOT_FOUND) {
$responseBody = json_decode($e
->getResponse()
->getBody(), TRUE);
$message = $responseBody['messages'][0];
throw new LingotekDocumentNotFoundException($message, Response::HTTP_NOT_FOUND);
}
throw new LingotekApiException(new FormattableMarkup('Failed to get document: %message', [
'%message' => $e
->getMessage(),
]), $e
->getCode(), $e);
} catch (\Exception $e) {
throw new LingotekApiException(new FormattableMarkup('Failed to get document: %message', [
'%message' => $e
->getMessage(),
]));
}
return $response
->getBody()
->getContents();
}