public function ImageHotspotsController::createAction in Image Hotspots 8
Creates hotspot with values from request data.
Parameters
\Symfony\Component\HttpFoundation\Request $request: Request from user to change hotspot.
Return value
\Drupal\Core\Ajax\AjaxResponse AjaxResponse
1 string reference to 'ImageHotspotsController::createAction'
File
- src/
Controller/ ImageHotspotsController.php, line 61
Class
- ImageHotspotsController
- Class ImageHotspotsController.
Namespace
Drupal\image_hotspots\ControllerCode
public function createAction(Request $request) {
if (!$this
->accessCallback()) {
$code = 403;
$parameters['error'] = $this
->t('You did a lot actions with hotspots and can not create hotspot right now. Wait some seconds before you can do it again.');
}
else {
$parameters = $request->request
->all();
$parameters['title'] = preg_replace('/(javascript)+(\\s)*:+/', '', Xss::filter($parameters['title']));
$parameters['description'] = preg_replace('/(javascript)+(\\s)*:+/', '', Xss::filter($parameters['description']));
$parameters['link'] = preg_replace('/(javascript)+(\\s)*:+/', '', Xss::filter($parameters['link']));
$parameters['target'] = preg_replace('/(javascript)+(\\s)*:+/', '', Xss::filter($parameters['target']));
$parameters['uid'] = $this
->currentUser()
->id();
try {
$hotspot = ImageHotspot::create($parameters);
$hotspot
->save();
$this
->disableCache($hotspot
->getTarget());
$code = 200;
$parameters['hid'] = $hotspot
->id();
} catch (EntityStorageException $e) {
$code = 500;
$parameters['error'] = $e
->getMessage();
}
}
return new AjaxResponse($parameters, $code);
}