src/EventSubscriber/EasyAdminWebPageSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\WebPage;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
  7. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  8. class EasyAdminWebPageSubscriber implements EventSubscriberInterface
  9. {
  10.     protected $container;
  11.     protected $webContentSEOService;
  12.     protected $webContentArticleService;
  13.     
  14.     protected $webContentUserService;
  15.     
  16.     public function __construct(ContainerInterface $container)
  17.     {
  18.         $this->container $container;
  19.         $this->webContentSEOService $this->container->get('app.web_content.seo');
  20.         $this->webContentWebPageService $this->container->get('app.web_content.web_page');
  21.         $this->webContentUserService $this->container->get('app.web_content.user');
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             BeforeEntityPersistedEvent::class => ['setNewWebPage'],
  27.             BeforeEntityUpdatedEvent::class => ['setEditWebPage']
  28.         ];
  29.     }
  30.     public function setNewWebPage(BeforeEntityPersistedEvent $event)
  31.     {
  32.         $entity $event->getEntityInstance();
  33.         if (!($entity instanceof WebPage)) {
  34.             return;
  35.         }
  36.         $this->webContentWebPageService->moreData($entity);
  37.         $this->webContentSEOService->defineMetaData($entity);
  38.         $this->webContentUserService->defineAuthor($entity);
  39.     }
  40.     public function setEditWebPage(BeforeEntityUpdatedEvent $event)
  41.     {
  42.         $entity $event->getEntityInstance();
  43.         if (!($entity instanceof WebPage)) {
  44.             return;
  45.         }
  46.         $this->webContentWebPageService->moreData($entity);
  47.         $this->webContentSEOService->defineMetaData($entity);
  48.         $this->webContentUserService->defineAuthor($entity);
  49.     }
  50. }