src/EventListener/RemoveListener.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Entity\Attachment;
  4. use Vich\UploaderBundle\Event\Event;
  5. use Vich\UploaderBundle\Event\Events;
  6. /**
  7.  * {@inheritDoc}
  8.  */
  9. class RemoveListener
  10. {
  11.     /**
  12.      * Returns an array of events this subscriber wants to listen to.
  13.      *
  14.      * @return array
  15.      */
  16.     public function getSubscribedEvents()
  17.     {
  18.         return [Events::POST_REMOVE => 'postRemove'];
  19.     }
  20.     /**
  21.      * @param Event $event
  22.      */
  23.     public function onVichuploaderPreremove(Event $event)
  24.     {
  25.         /** @var Attachment $object */
  26.         $object $event->getObject();
  27.         if ($practicalFile $object->getPracticalFile()) {
  28.             $practicalFile->removeAttachment($object);
  29.         }
  30.         if ($summary $object->getSummary()) {
  31.             $summary->removeAttachment($object);
  32.         }
  33.         if ($practicalDossier $object->getPracticalDossier()) {
  34.             $practicalDossier->removeAttachment($object);
  35.         }
  36.     }
  37. }