score:4

Accepted answer

You have to define a service that reference your extended handler class and point it in app/config.yml. e.g

The class,

//namespace definitions
class MyHandler extends RegistrationFormHandler{

    private $container;

    public function __construct(Form $form, Request $request, UserManagerInterface $userManager, MailerInterface $mailer, ContainerInterface $container)
    {
        parent::__construct($form, $request, $userManager, $mailer);
        $this->container = $container;
    }

    protected function onSuccess(UserInterface $user, $confirmation)
    {
        $repository = $this->container->get('doctrine')->getEntityManager()->getRepository('AcmeUserBundle:Photo');

        // your code

    }

The service,

 my.registration.form.handler:
    scope: request
    class: FQCN\Of\MyHandler
    arguments: [@fos_user.registration.form, @request, @fos_user.user_manager, @fos_user.mailer, @service_container]

Lastly in app/config.yml,

fos_user:
    #....
    registration:
      #...
      form:
        handler: my.registration.form.handler

score:-1

FOS got his own UserManager. Try to use this.


Related Query

More Query from same tag