Created
June 28, 2013 13:48
-
-
Save ornj/5884801 to your computer and use it in GitHub Desktop.
EventListener for removing entries in Taggable when using FabienPennequin/FPNTagBundle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Bundle\TagBundle\EventListener; | |
use Doctrine\ORM\Event\LifecycleEventArgs; | |
use Application\Bundle\TagBundle\Entity\Tag; | |
class DeleteTagging | |
{ | |
public function preRemove(LifecycleEventArgs $args) | |
{ | |
$entity = $args->getEntity(); | |
$em = $args->getEntityManager(); | |
if ($entity instanceof Tag) { | |
$resources = $em->getRepository('ApplicationTagBundle:Tagging')->findBy(array( | |
'tag' => $entity, | |
)); | |
foreach ($resources as $resource) { | |
$em->remove($resource); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Application\Bundle\TagBundle\Resources\config\services.yml | |
services: | |
application_tag.remove_listener: | |
class: application\Bundle\TagBundle\EventListener\DeleteTagging | |
tags: | |
- { name: doctrine.event_listener, event: preRemove } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment