<?php
namespace App\EventSubscriber;
use App\Entity\Offre;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
class EasyAdminSubscriberOffreDate implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
BeforeEntityPersistedEvent::class => ['setEntityCreatedAt']
];
}
/**
* @param BeforeEntityPersistedEvent $event
* @return void
*/
public function setEntityCreatedAt(BeforeEntityPersistedEvent $event): void
{
$offre = $event->getEntityInstance();
if (!($offre instanceof Offre)) {
return;
}
$offre->setCreatedAt(new \DateTime());
}
}