<?php
namespace App\EventSubscriber;
use App\Entity\Gazette;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EasyAdminSubscriberGazettePublished implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
BeforeEntityPersistedEvent::class => ['setGazettePublished'],
];
}
public function setGazettePublished(BeforeEntityPersistedEvent $event)
{
$gazette = $event->getEntityInstance();
if (!($gazette instanceof Gazette)) {
return;
}
$gazette->setPublishedAt(new \DateTime());
}
}