<?php
namespace App\EventListener;
use App\Entity\Attachment;
use Vich\UploaderBundle\Event\Event;
use Vich\UploaderBundle\Event\Events;
/**
* {@inheritDoc}
*/
class RemoveListener
{
/**
* Returns an array of events this subscriber wants to listen to.
*
* @return array
*/
public function getSubscribedEvents()
{
return [Events::POST_REMOVE => 'postRemove'];
}
/**
* @param Event $event
*/
public function onVichuploaderPreremove(Event $event)
{
/** @var Attachment $object */
$object = $event->getObject();
if ($practicalFile = $object->getPracticalFile()) {
$practicalFile->removeAttachment($object);
}
if ($summary = $object->getSummary()) {
$summary->removeAttachment($object);
}
if ($practicalDossier = $object->getPracticalDossier()) {
$practicalDossier->removeAttachment($object);
}
}
}