Do not override the controller. You should use the event system! Create an event handler which subscribe to FOSUserEvents::REGISTRATION_COMPLETE
and then perform the role addition.
Documentation:
- Symfony:
EventDispatcher
component - Symfony: Using events
- FOSUserBundle: Hooking into the controllers
The listener:
class RegistrationListener implements EventSubscriberInterface
{
public function __construct(/* ... */)
{
// ...
}
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_COMPLETE => 'addRole',
);
}
public function addRole(FilterUserResponseEvent $event)
{
$user = $event->getUser();
// Add the role here
// ...
}
}
The service definition:
<service id="my_app.event.registration" class="MyApp\Event\RegistrationListener">
<tag name="kernel.event_subscriber" />
<!-- ... -->
</service>