<?php
namespace App\EventSubscriber;
use App\Entity\BlogArticle;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class EasyAdminSubscriberBlogUpdated implements EventSubscriberInterface
{
/**
* @return string[][]
*/
public static function getSubscribedEvents(): array
{
return [
BeforeEntityUpdatedEvent::class => ['setBlogUpdatedAt'],
];
}
/**
* @param BeforeEntityUpdatedEvent $event
* @return void
*/
public function setBlogUpdatedAt(BeforeEntityUpdatedEvent $event): void
{
$blog = $event->getEntityInstance();
if (!($blog instanceof BlogArticle)) {
return;
}
$blog->setUpdatedAt(new \DateTime());
}
}