contextly-8.x-2.1/src/Controller/ContextlyAjaxEditorRequestController.php
src/Controller/ContextlyAjaxEditorRequestController.php
<?php
namespace Drupal\contextly\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Drupal\contextly\Contextly\ContextlyDrupalKit;
/**
* The ContextlyAjaxEditorRequestController class.
*/
class ContextlyAjaxEditorRequestController extends ControllerBase {
/**
* Request.
*
* @return string
* Return Hello string.
*/
public function request($request,
$node) {
try {
// Build parameters list.
$params = $_POST;
$params['custom_id'] = $node->id();
/** @var \Drupal\contextly\Contextly\ContextlyDrupalKit $kit */
$kit = ContextlyDrupalKit::getInstance();
// Handle the request.
$result = $kit->newWidgetsEditor()->handleRequest($request, $params);
// Deliver results to the client.
return new JsonResponse($result);
}
catch (\ContextlyKitException $e) {
$this->getLogger('contextly')->error($e);
$this->messenger()->addError($e->getMessage());
return new JsonResponse([
'error' => 'Unknown error',
]);
}
}
/**
* Snippet.
*/
public function handle($mode,
$node) {
// Needs safari and firefox properly working on apple platform.
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header('X-Frame-Options: SAMEORIGIN');
// @todo check $node why is in url.
/** @var \Drupal\contextly\Contextly\ContextlyDrupalKit $kit */
$kit = ContextlyDrupalKit::getInstance();
print $kit->newOverlayDialog($mode)->render();
exit;
}
}
