vendor/kunstmaan/admin-bundle/EventListener/CloneListener.php line 17

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\AdminBundle\EventListener;
  3. use Kunstmaan\AdminBundle\Entity\AbstractEntity;
  4. use Kunstmaan\AdminBundle\Entity\DeepCloneInterface;
  5. use Kunstmaan\AdminBundle\Event\DeepCloneAndSaveEvent;
  6. /**
  7.  * This listener will make sure the id isn't copied for AbstractEntities
  8.  */
  9. class CloneListener
  10. {
  11.     /**
  12.      * @param DeepCloneAndSaveEvent $event
  13.      */
  14.     public function onDeepCloneAndSave(DeepCloneAndSaveEvent $event)
  15.     {
  16.         $clonedEntity $event->getClonedEntity();
  17.         if ($clonedEntity instanceof AbstractEntity) {
  18.             $clonedEntity->setId(null);
  19.         }
  20.         if ($clonedEntity instanceof DeepCloneInterface) {
  21.             $clonedEntity->deepClone();
  22.         }
  23.     }
  24. }