src/EventSubscriber/EasyAdminSubscriberBlogUpdated.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Entity\BlogArticle;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class EasyAdminSubscriberBlogUpdated implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @return string[][]
  10.      */
  11.     public static function getSubscribedEvents(): array
  12.     {
  13.         return [
  14.             BeforeEntityUpdatedEvent::class => ['setBlogUpdatedAt'],
  15.         ];
  16.     }
  17.     /**
  18.      * @param BeforeEntityUpdatedEvent $event
  19.      * @return void
  20.      */
  21.     public function setBlogUpdatedAt(BeforeEntityUpdatedEvent $event): void
  22.     {
  23.         $blog $event->getEntityInstance();
  24.         if (!($blog instanceof BlogArticle)) {
  25.             return;
  26.         }
  27.         $blog->setUpdatedAt(new \DateTime());
  28.     }
  29. }