Search code examples
formssymfonysonata-adminsonata

extending sonata user bundle with more form fields, get Could not load type "Application\Sonata\UserBundle\Form\RegistrationType"


I'm trying to extend the registration form to show more fields, but after trying multiple variations, I think either there's a bug, or the configuration settings I'm seeing on tutorials and posts are not correct for symfony 2.7 it's driving me nuts, thinking maybe wait till I upgrade to version 3.4, but upgrade isn't going smoothly so far.

error -

Could not load type 
                  "Application\Sonata\UserBundle\Form\RegistrationType"

Form -

namespace Application\Sonata\UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array 
$options)
{

    $builder->add('firstname')
        ->add('dateOfBirth');
}

public function getParent()
{
    return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}

public function getBlockPrefix()
{
    return 'app_user_registration';
}

// For Symfony 2.x
public function getName()
{
    return $this->getBlockPrefix();
}

}

config_dev.yml

  fos_user:
      db_driver: orm 
      firewall_name: secured_area
      user_class: Application\Sonata\UserBundle\Entity\User
      registration:
          form:
             type: Application\Sonata\UserBundle\RegistrationType
      group:
         group_class: Application\Sonata\UserBundle\Entity\User

services.yml

        services:
          app.form.registration: 
          class: Application\Sonata\UserBundle\Form\RegistrationType
          arguments: [%fos_user.model.user.class%]
          tags:
          - { name: form.type, alias: app_user_registration }

So as mentioned it's symfony 2.7 and Sonata user-bundle 3.2 any help would be appreciated with this one

The part of code where it errors is this line in config_dev.yml

    registration:
      form:
         type: Application\Sonata\UserBundle\RegistrationType

routing.yml

       fos_user_register:
       resource: 
       "@FOSUserBundle/Resources/config/routing/registration.xml"
       prefix: /register

    #  sonata_user_register:
    # resource: 

   # 

 @SonataUserBundle/Resources/config/routing/sonata_registration_1.xml"

# prefix: /register

full config

    fos_user:
             db_driver: orm # other valid values are 
             'mongodb', 'couchdb' and 'propel'
              firewall_name: secured_area
              registration:
              form:
              type: eventsBundle\Form\RegistrationType
              user_class: 
              Application\Sonata\UserBundle\Entity\User
              group:
              group_class: Application\Sonata\UserBundle\Entity\User
              #group_manager: sonata.user.orm.group_manager                    
              # If you're using doctrine orm (use 
              Sonata.user.mongodb.group_manager for mongodb)

              service:
              user_manager: sonata.user.orm.user_manager                      
              # If you're using doctrine orm (use 
              sonata.user.mongodb.user_manager for mongodb)

Solution

  • Nothing from above worked in Symfony 2.7 for me. I upgraded to Symfony 3.4 and it now works!! perfectly following the standard guide https://symfony.com/doc/master/bundles/FOSUserBundle/overriding_forms.html an upgrade really was needed, probably the autowiring features helped.