1
votes

I installed FOSUserBundle and I extended registration and profile forms in order to meet my site look and feel, so now my forms for profile are in app\Resources\FOSUserBundle\views\Profile. Everything is working fine.

I added a few fields in my User entity, run doctrine:generate:entities and doctrine:schema:update and the db was correctly updated, but I don't know how to add this new fields in edit.html.twig inside the folder above, I simply expected to make it working adding them to the template.

thanks

2
What are modification brought to your FormType? please add some code so that you can get the maximum of help from the community - Adib Aroui

2 Answers

1
votes

You have to create your custom form first, such as this for example

// src/AppBundle/Form/UserType.php

namespace AppBundle\Form;

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

class UserType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('name');
    }

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

        // Or for Symfony < 2.8
        // return 'fos_user_profile_edit';
    }

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

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

Configure your form type as a service

# app/config/services.yml
services:
    app.form.profile:
        class: AppBundle\Form\UserType
        tags:
            - { name: form.type, alias: app_user_profile }

and your configuration file to extend/override

# app/config/config.yml
fos_user:
    # ...
    profile:
        form:
            type: AppBundle\Form\UserType
            # if you are using Symfony < 2.8 you should use the type name instead
            # type: app_user_profile
0
votes

You need to add to your UserType something like :

class UserType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */    
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder
            //for each new field
             ->add('myNewField')
         ;
     }
}

And then your field will be available in your Twig template. Hope this helps