src/Listener/RegistrationListener.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Listener;
  3. use FOS\UserBundle\Event\FormEvent;
  4. use FOS\UserBundle\FOSUserEvents;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class RegistrationListener implements EventSubscriberInterface
  7. {
  8.     public static function getSubscribedEvents()
  9.     {
  10.         return [
  11.             FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess',
  12.         ];
  13.     }
  14.     public function onRegistrationSuccess(FormEvent $event) {
  15.         $rolesArr = ['ROLE_USER''ROLE_FREELANCER'];
  16.         /** @var $user \FOS\UserBundle\Model\UserInterface */
  17.         $user $event->getForm()->getData();
  18.         $user->setRoles($rolesArr);
  19.     }
  20. }