public function LingotekNotificationController::endpoint in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 4.0.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.0.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.1.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.2.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.3.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.4.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.5.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.6.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.7.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
- 3.8.x src/Controller/LingotekNotificationController.php \Drupal\lingotek\Controller\LingotekNotificationController::endpoint()
1 string reference to 'LingotekNotificationController::endpoint'
- lingotek.routing.yml in ./lingotek.routing.yml
- lingotek.routing.yml
File
- src/Controller/LingotekNotificationController.php, line 21
Class
- LingotekNotificationController
- Returns responses for lingotek module setup routes.
Namespace
Drupal\lingotek\Controller
Code
public function endpoint(Request $request) {
$content_translation_service = \Drupal::service('lingotek.content_translation');
$config_translation_service = \Drupal::service('lingotek.config_translation');
$translation_service = $content_translation_service;
$request_method = $request
->getMethod();
$http_status_code = Response::HTTP_NOT_IMPLEMENTED;
$type = $request
->get('type');
$result = array();
$messages = array();
$security_token = $request
->get('security_token');
if ($security_token == 1) {
$http_status_code = Response::HTTP_NOT_IMPLEMENTED;
}
parse_str($request
->getQueryString(), $params);
switch ($type) {
case 'project':
break;
case 'document':
break;
case 'document_uploaded':
$entity = $this
->getEntity($request
->get('document_id'));
$profile = $this
->getProfile($entity);
if ($entity) {
if ($entity instanceof ConfigEntityInterface) {
$translation_service = $config_translation_service;
}
$http_status_code = Response::HTTP_OK;
$translation_service
->setSourceStatus($entity, Lingotek::STATUS_CURRENT);
$result['request_translations'] = $profile
->hasAutomaticUpload() ? $translation_service
->requestTranslations($entity) : [];
}
else {
$http_status_code = Response::HTTP_NOT_FOUND;
}
break;
case 'phase':
case 'target':
$entity = $this
->getEntity($request
->get('document_id'));
$profile = $this
->getProfile($entity);
if ($entity) {
if ($entity instanceof ConfigEntityInterface) {
$translation_service = $config_translation_service;
}
$http_status_code = Response::HTTP_OK;
$locale = $request
->get('locale');
$langcode = $this->languageLocaleMapper
->getConfigurableLanguageForLocale($locale)
->id();
$result['set_target_status'] = $translation_service
->setTargetStatus($entity, $langcode, Lingotek::STATUS_READY);
$result['download'] = $profile
->hasAutomaticDownloadForTarget($langcode) ? $translation_service
->downloadDocument($entity, $locale) : FALSE;
}
else {
$http_status_code = Response::HTTP_NOT_FOUND;
$messages[] = "Document not found.";
}
break;
default:
$http_status_code = Response::HTTP_NOT_IMPLEMENTED;
$messages[] = "Not implemented.";
break;
}
$response = array(
'service' => 'notify',
'method' => $request_method,
'params' => $params,
'result' => $result,
'messages' => $messages,
);
return JsonResponse::create($response, $http_status_code);
}