public function ImageHotspotsController::translateAction in Image Hotspots 8
Translate hotspot with $hid.
Parameters
$hid: Hotspot id.
$langcode: Language ID.
\Symfony\Component\HttpFoundation\Request $request:
Return value
\Drupal\Core\Ajax\AjaxResponse
1 string reference to 'ImageHotspotsController::translateAction'
File
- src/
Controller/ ImageHotspotsController.php, line 156
Class
- ImageHotspotsController
- Class ImageHotspotsController.
Namespace
Drupal\image_hotspots\ControllerCode
public function translateAction($hid, $langcode, Request $request) {
if (!$this
->accessCallback()) {
$code = 403;
$parameters['error'] = $this
->t('You did a lot actions with hotspots and can not update this hotspot right now. Wait some seconds before you can do it again.');
}
else {
/** @var ImageHotspotInterface $hotspot */
$hotspot = ImageHotspot::load($hid);
if (is_null($hotspot)) {
$code = 404;
$parameters['error'] = $this
->t('Can not find hotspot with hid ') + $hid;
}
else {
if ($hotspot
->hasTranslation($langcode)) {
$hotspot = $hotspot
->getTranslation($langcode);
}
else {
$hotspot = $hotspot
->addTranslation($langcode);
}
$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']));
$hotspot
->setTitle($parameters['title']);
$hotspot
->setDescription($parameters['description']);
$hotspot
->setLink($parameters['link']);
try {
$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);
}