You are here

public function ImageHotspotsController::deleteAction in Image Hotspots 8

Deletes hotspot with $hid.

Parameters

string $hid: Hotspot id.

Return value

\Drupal\Core\Ajax\AjaxResponse AjaxResponse

1 string reference to 'ImageHotspotsController::deleteAction'
image_hotspots.routing.yml in ./image_hotspots.routing.yml
image_hotspots.routing.yml

File

src/Controller/ImageHotspotsController.php, line 28

Class

ImageHotspotsController
Class ImageHotspotsController.

Namespace

Drupal\image_hotspots\Controller

Code

public function deleteAction($hid) {
  if (!$this
    ->accessCallback()) {
    $code = 403;
    $data = $this
      ->t('You did a lot actions with hotspots and can not delete this hotspot right now. Wait some seconds before you can do it again.');
  }
  else {
    try {

      /** @var \Drupal\image_hotspots\Entity\ImageHotspot $hotspot */
      $hotspot = ImageHotspot::load($hid);
      $target = $hotspot
        ->getTarget();
      $hotspot
        ->delete();
      $this
        ->disableCache($target);
      $code = 200;
      $data = $this
        ->t('Hotspot was successfully deleted');
    } catch (EntityStorageException $e) {
      $code = 500;
      $data = $e
        ->getMessage();
    }
  }
  return new AjaxResponse($data, $code);
}