src/Flexy/FrontBundle/EventSubscriber/EasyAdminSubscriber.php line 58
<?php
# src/EventSubscriber/EasyAdminSubscriber.php
namespace App\Flexy\FrontBundle\EventSubscriber;
use App\Entity\BlogPost;
use App\Flexy\FrontBundle\Entity\Menu;
use App\Flexy\FrontBundle\Entity\MenuItem;
use App\Flexy\ShopBundle\Entity\Brand;
use App\Flexy\ShopBundle\Entity\Order\DemandeFund;
use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
use App\Flexy\ShopBundle\Entity\Product\ImportExcel;
use App\Flexy\ShopBundle\Entity\Product\Product;
use App\Flexy\ShopBundle\Entity\Product\ProductShop;
use App\Flexy\ShopBundle\Entity\Resource\Agent;
use App\Flexy\ShopBundle\Entity\Vendor\Vendor;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityDeletedEvent;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use App\Flexy\FrontBundle\Entity\Page;
class EasyAdminSubscriber implements EventSubscriberInterface
{
private readonly \Doctrine\Persistence\ObjectManager $em;
public function __construct(private readonly Security $security,ManagerRegistry $doctrine)
{
$this->em = $doctrine->getManager();
}
public static function getSubscribedEvents()
{
return [
BeforeEntityPersistedEvent::class => ['beforePersist'],
BeforeEntityUpdatedEvent::class => ['beforeUpdated'],
BeforeEntityDeletedEvent::class => ['beforeDeleted'],
];
}
public function beforePersist(BeforeEntityPersistedEvent $event)
{
$entity = $event->getEntityInstance();
}
public function beforeUpdated(BeforeEntityUpdatedEvent $event)
{
$entity = $event->getEntityInstance();
if ($entity instanceof Page) {
//dd($entity);
}
if ($entity instanceof Menu) {
foreach($entity->getMenuItems() as $singleMenuItem){
foreach($singleMenuItem->getSubMenuItems() as $singleSubMenuItem){
$singleSubMenuItem->setMenu($entity);
$singleSubMenuItem->setParentMenuItem($singleMenuItem);
$entity->addMenuItem($singleSubMenuItem);
$this->em->persist($singleSubMenuItem);
}
}
if($entity->getIsMainMenu()){
//$this->em->getRepository(Menu::class)->setMainMenu($entity);
}
}
}
public function beforeDeleted(BeforeEntityDeletedEvent $event)
{
}
}