public function LingotekSetupController::handshake in Lingotek Translation 4.0.x
Same name and namespace in other branches
- 8 src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 8.2 src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.0.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.1.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.2.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.3.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.4.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.5.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.6.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.7.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
- 3.8.x src/Controller/LingotekSetupController.php \Drupal\lingotek\Controller\LingotekSetupController::handshake()
1 string reference to 'LingotekSetupController::handshake'
File
- src/
Controller/ LingotekSetupController.php, line 34
Class
- LingotekSetupController
- Returns responses for lingotek module setup routes.
Namespace
Drupal\lingotek\ControllerCode
public function handshake(Request $request) {
if (Request::METHOD_POST === $request
->getMethod()) {
$body = Json::decode($request
->getContent());
if (isset($body['access_token'])) {
$accountConfig = \Drupal::configFactory()
->getEditable('lingotek.account');
$accountConfig
->set('access_token', $body['access_token']);
$accountConfig
->save();
$account_info = $this
->fetchAccountInfo();
$this
->saveAccountInfo($account_info);
$this
->messenger()
->addStatus($this
->t('Your account settings have been saved.'));
$this->logger
->notice('Account connected to Lingotek.');
return new JsonResponse([
'status' => TRUE,
'message' => 'Account connected to Lingotek.',
]);
}
else {
return new JsonResponse([
'status' => FALSE,
'message' => 'Account not connected to Lingotek.',
]);
}
}
elseif (Request::METHOD_GET === $request
->getMethod()) {
// Is a GET.
$accountConfig = \Drupal::config('lingotek.account');
if ($accountConfig
->get('access_token')) {
// No need to show the username and token if everything worked correctly
// Just go to the community page
return $this
->redirect('lingotek.setup_community');
}
// Is a GET, but don't have the token yet.
return [
'#type' => 'markup',
'#markup' => $this
->t('Connecting... Please wait to be redirected'),
'#attached' => [
'library' => [
'lingotek/lingotek.connect',
],
],
];
}
}