0
votes

I have created an ORM user class and I added a new attribute called "name". I have created a new RegistrationFormType also. The problem is the registration form display only the new field "name" and other fields (email, usreneme, password ') provided by FOSuserBundle are hidden.

// src/Boutique/UserBundle/Form/RegistrationFormType.php
<?php

namespace Boutique\UserBundle\Form;

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

use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('name', 'text')
    ;
}   

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'Boutique\UserBundle\Entity\User'
    ));
}

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

config.yml

fos_user:
db_driver: orm 
firewall_name: main 
user_class: Boutique\UserBundle\Entity\User 
registration:
    confirmation:
        from_email: # Use this node only if you don't want the global email address for the confirmation email
            address:        [email protected]
            sender_name:    no-reply
        enabled:    false # change to true for required email confirmation
        template:   FOSUserBundle:Registration:email.txt.twig
    form:
        type:               boutique_user_registration
        name:               fos_user_registration_form
        validation_groups:  [Registration, Default]

services.yml

services:
boutique_user.registration.form.type:
    class: Boutique\UserBundle\Form\RegistrationFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: boutique_user_registration }
1
I have forgot parent::buildForm($builder, $options);hous

1 Answers

0
votes

You can simply override the default RegistrationFormType.php by defining your custom UserBundle as a child of FOSUserBundle:

<?php

namespace Boutique\UserBundle\Form;;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class BoutiqueUserBundle extends Bundle
{
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}

Then to override the FormType just copy /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Form/Type/ResettingFormType.php to /src/Boutique/UserBundle/Form/Type/RegistrationFormType.php. Add your name field and your done.