src/EventSubscriber/AdminSubscriber.php line 30
<?php
namespace App\EventSubscriber;
use App\Entity\Shop;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
class AdminSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
BeforeEntityPersistedEvent::class => ['setCreatedAt'],
BeforeEntityUpdatedEvent::class => ['setUpdatedAt']
];
}
public function setCreatedAt(BeforeEntityPersistedEvent $event)
{
$entityInstance = $event->getEntityInstance();
if (!$entityInstance instanceof Shop) return;
$entityInstance->setCreatedAt(new \DateTime());
}
public function setUpdatedAt(BeforeEntityUpdatedEvent $event)
{
$entityInstance = $event->getEntityInstance();
if (!$entityInstance instanceof Shop) return;
$entityInstance->setUpdatedAt(new \DateTime());
}
}