src/EventSubscriber/EasyAdminSubscriberGazettePublished.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\Gazette;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class EasyAdminSubscriberGazettePublished implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         return [
  11.             BeforeEntityPersistedEvent::class => ['setGazettePublished'],
  12.         ];
  13.     }
  14.     public function setGazettePublished(BeforeEntityPersistedEvent $event)
  15.     {
  16.         $gazette $event->getEntityInstance();
  17.         if (!($gazette instanceof Gazette)) {
  18.             return;
  19.         }
  20.         $gazette->setPublishedAt(new \DateTime());
  21.     }
  22. }