Skip to content

Instantly share code, notes, and snippets.

@ornj
Created June 28, 2013 13:48
Show Gist options
  • Save ornj/5884801 to your computer and use it in GitHub Desktop.
Save ornj/5884801 to your computer and use it in GitHub Desktop.
EventListener for removing entries in Taggable when using FabienPennequin/FPNTagBundle.
<?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);
}
}
}
}
# 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