<?php
namespace App\EventSubscriber;
use Sylius\Component\Customer\Model\CustomerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
final class UserRegistrationFormSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
FormEvents::SUBMIT => 'submit',
];
}
public function submit(FormEvent $event)
{
$customer = $event->getData();
if (!$customer instanceof CustomerInterface) {
throw new UnexpectedTypeException($customer, CustomerInterface::class);
}
if (null !== $user = $customer->getUser()) {
$user->setEnabled(true);
}
}
}