|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
-
- namespace Lc\SovBundle\EventSubscriber;
-
- use Doctrine\ORM\EntityManagerInterface;
-
- use Lc\SovBundle\Doctrine\EntityInterface;
- use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
- use Lc\SovBundle\Doctrine\Extension\SortableInterface;
- use Lc\SovBundle\Doctrine\Extension\StatusInterface;
- use Lc\SovBundle\Doctrine\Extension\TreeInterface;
- use Lc\SovBundle\Event\EntityComponentEvent;
- use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
- use Lc\SovBundle\Repository\AbstractRepositoryInterface;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
- class SluggablePropertyEventSubscriber implements EventSubscriberInterface
- {
- protected $em;
- protected $adminUrlGenerator;
-
- public function __construct(EntityManagerInterface $entityManager)
- {
- $this->em = $entityManager;
- }
-
- public static function getSubscribedEvents()
- {
- return [
- EntityComponentEvent::DUPLICATE_EVENT => ['setSluggablePropertyDuplicateEvent'],
- EntityManagerEvent::POST_UPDATE_EVENT => ['setSluggablePropertyUpdateEvent'],
- ];
- }
-
- public function setSluggablePropertyDuplicateEvent(EntityComponentEvent $event)
- {
- $entity = $event->getEntity();
- if ($entity instanceof SluggableInterface) {
- $entity->clearId(null);
- $entity->setSlug(null);
- }
- }
-
- public function setSluggablePropertyUpdateEvent(EntityManagerEvent $event)
- {
- $entity = $event->getEntity();
- if ($entity instanceof SluggableInterface) {
- $entity->setSlug(null);
- }
- }
-
- }
|