Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SluggablePropertyEventSubscriber.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Lc\SovBundle\EventSubscriber;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Doctrine\EntityInterface;
  5. use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
  6. use Lc\SovBundle\Doctrine\Extension\SortableInterface;
  7. use Lc\SovBundle\Doctrine\Extension\StatusInterface;
  8. use Lc\SovBundle\Doctrine\Extension\TreeInterface;
  9. use Lc\SovBundle\Event\EntityComponentEvent;
  10. use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
  11. use Lc\SovBundle\Repository\AbstractRepositoryInterface;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class SluggablePropertyEventSubscriber implements EventSubscriberInterface
  14. {
  15. protected $em;
  16. protected $adminUrlGenerator;
  17. public function __construct(EntityManagerInterface $entityManager)
  18. {
  19. $this->em = $entityManager;
  20. }
  21. public static function getSubscribedEvents()
  22. {
  23. return [
  24. EntityComponentEvent::DUPLICATE_EVENT => ['setSluggablePropertyDuplicateEvent'],
  25. EntityManagerEvent::POST_UPDATE_EVENT => ['setSluggablePropertyUpdateEvent'],
  26. ];
  27. }
  28. public function setSluggablePropertyDuplicateEvent(EntityComponentEvent $event)
  29. {
  30. $entity = $event->getEntity();
  31. if ($entity instanceof SluggableInterface) {
  32. $entity->clearId(null);
  33. $entity->setSlug(null);
  34. }
  35. }
  36. public function setSluggablePropertyUpdateEvent(EntityManagerEvent $event)
  37. {
  38. $entity = $event->getEntity();
  39. if ($entity instanceof SluggableInterface) {
  40. $entity->setSlug(null);
  41. }
  42. }
  43. }