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