<?php
// src/Form/EventListener/RegistrationSubscriber.php
namespace App\Form\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use App\Entity\User;
class RegistrationSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
FormEvents::SUBMIT => 'onSubmit',
];
}
public function onSubmit(FormEvent $event): void
{
$entity = $event->getData();
if($entity instanceof User) {
$entity->setRoles(['ROLE_ADMIN']);
$date = new \DateTime();
$entity->setCreatedAt($date);
$entity->setUpdatedAt($date);
}
}
}