src/EventSubscriber/EasyAdminSubscriber.php line 31
<?phpnamespace App\EventSubscriber;use App\Entity\Order;use App\Enum\NotificationContent;use App\Service\SendEmailNotification;use DateTimeImmutable;use Doctrine\ORM\EntityManagerInterface;use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityUpdatedEvent;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class EasyAdminSubscriber implements EventSubscriberInterface{private $manager;public function __construct(EntityManagerInterface $manager, private SendEmailNotification $email){$this->manager = $manager;}public static function getSubscribedEvents(){return [BeforeEntityUpdatedEvent::class => ['addDeliveryDate'],];}public function addDeliveryDate(BeforeEntityUpdatedEvent $event){$entity = $event->getEntityInstance();if (!($entity instanceof Order)) {return;}if ($entity->getStatus() == 'livred') {$entity->setLivredAt(new DateTimeImmutable());}if ($entity->getStatus() == 'orderCanceled') {$this->email->sendBoth(NotificationContent::ORDERCANCELED, $entity);}if ($entity->getStatus() == 'refund') {$this->email->sendBoth(NotificationContent::ORDERREFUND, $entity);}}}