src/Flexy/FrontBundle/EventSubscriber/EasyAdminSubscriber.php line 95

  1. <?php 
  2. # src/EventSubscriber/EasyAdminSubscriber.php
  3. namespace App\Flexy\FrontBundle\EventSubscriber;
  4. use App\Entity\BlogPost;
  5. use App\Flexy\FrontBundle\Entity\Menu;
  6. use App\Flexy\FrontBundle\Entity\MenuItem;
  7. use App\Flexy\ShopBundle\Entity\Brand;
  8. use App\Flexy\ShopBundle\Entity\Order\DemandeFund;
  9. use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
  10. use App\Flexy\ShopBundle\Entity\Product\ImportExcel;
  11. use App\Flexy\ShopBundle\Entity\Product\Product;
  12. use App\Flexy\ShopBundle\Entity\Product\ProductShop;
  13. use App\Flexy\ShopBundle\Entity\Resource\Agent;
  14. use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
  15. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  16. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\Security\Core\Security;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Doctrine\Persistence\ManagerRegistry;
  21. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityDeletedEvent;
  22. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  23. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  24. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  25. use App\Flexy\FrontBundle\Entity\Page;
  26. class EasyAdminSubscriber implements EventSubscriberInterface
  27. {
  28.     private readonly \Doctrine\Persistence\ObjectManager $em;
  29.     public function __construct(private readonly Security $security,ManagerRegistry $doctrine)
  30. {
  31.         $this->em $doctrine->getManager();
  32.     }
  33.     public static function getSubscribedEvents()
  34.     {
  35.         return [
  36.             BeforeEntityPersistedEvent::class => ['beforePersist'],
  37.             BeforeEntityUpdatedEvent::class => ['beforeUpdated'],
  38.             BeforeEntityDeletedEvent::class => ['beforeDeleted'],
  39.         ];
  40.     }
  41.     public function beforePersist(BeforeEntityPersistedEvent $event)
  42.     {
  43.         $entity $event->getEntityInstance();
  44.         
  45.        
  46.      
  47.     }
  48.     public function beforeUpdated(BeforeEntityUpdatedEvent $event)
  49.     {
  50.         $entity $event->getEntityInstance();
  51.         
  52.         if ($entity instanceof Page) {
  53.             //dd($entity);
  54.         }
  55.         if ($entity instanceof Menu) {
  56.             
  57.             
  58.             
  59.             
  60.             foreach($entity->getMenuItems() as $singleMenuItem){
  61.                 
  62.                 foreach($singleMenuItem->getSubMenuItems() as $singleSubMenuItem){
  63.                     
  64.                     $singleSubMenuItem->setMenu($entity);
  65.                     $singleSubMenuItem->setParentMenuItem($singleMenuItem);
  66.                     
  67.                     $entity->addMenuItem($singleSubMenuItem);
  68.                     $this->em->persist($singleSubMenuItem);
  69.                 }
  70.             }
  71.             
  72.             if($entity->getIsMainMenu()){
  73.                 //$this->em->getRepository(Menu::class)->setMainMenu($entity);
  74.             }
  75.            
  76.         }
  77.    
  78.      
  79.     }
  80.     public function beforeDeleted(BeforeEntityDeletedEvent $event)
  81.     {
  82.        
  83.     }
  84. }