Search code examples
symfonysonatasonata-user-bundlesymfony-2.8

Overriding Registration Form (SonataUserBundle) since Symfony2 Update to 2.8


After updating symfony2 with the dependencies to 2.8 I get the following error message when trying to override the sonata user bundle registration form:

The field type "Sonata\UserBundle\Form\Type\RegistrationFormType" is not registered with the service container.

If I switch back to Symfony 2.7 everything works again.

My services.yml:

sonata.user.registration.form.type:
    class: My\Bundle\Form\Type\RegistrationFormType
    arguments: [ "%fos_user.model.user.class%" , "@service_container"]
    tags:
        - { name: form.type, alias: sonata_user_registration }

In my controller the following line triggers the error:

$form = $this->container->get( 'sonata.user.registration.form' );

Unfortunately I couldn't find any resources on this subject (i.e. if there are any changes in overriding the registration form since the latest version)


Solution

  • Ok, this isn't a bug, but a new feature. You have to use the build() and boot() methods in your bundle to register your FormType via FormHelper::registerFormTypeMapping.