Could not load type "XYZ" error when overriding FOSUserBundle form types

1.7k Views Asked by At

I am attempting to override the RegistrationFormType in the Symfony2 FOSUserBundle. I am following the documentation and believe i've covered everything. I've created a bundle to contain my overrides to the FOSUserBundle and the following code is from this bundle as well as the application config.

Has anyone experienced this when overriding FOSUserBundle, or see anything in my code that would help explain why I keep getting this error. I'm on symfony v2.0.4

RegistrationFormType.php

<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Thrive\SaasBundle\Form\Type;

use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('firstname', null, array('error_bubbling' => true))
            ->add('lastname', null, array('error_bubbling' => true))
            ->add('company', null, array('error_bubbling' => true))
            ->add('email', 'email', array('error_bubbling' => true))
            ->add('username', null, array('error_bubbling' => true))
            ->add('plainPassword', 'repeated', array('type' => 'password', 'error_bubbling' => true))
            ;
    }

    public function getName()
    {
        return 'thrive_user_registration';
    }

}

Services.yml

services:
  thrive_saas_registration.form.type:
    class: Thrive\SaasBundle\Form\Type\RegistrationFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: thrive_user_registration}

Application's Config File

fos_user:
     ...
    registration: 
      form:
        type: thrive_user_registration
2

There are 2 best solutions below

1
On BEST ANSWER

Turns out my services.yml file wasn't being loaded via dependency injection. After digging around i realized my extension.php file for this bundle was named incorrectly. Early on I had renamed the bundle and made a typo when renaming the extension.php file inside the DependencyInjection folder. After correcting the mispelling everything works again.

3
On

Did you tried to just add one new field and look if it works?

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('name');
}

Also remember to clear your prod cache if you're testing from there...