Fosuserbundle: How to override FOSUserBundle ProfileFormType -- Symfony 3.1?

Created on 2 Jun 2016  路  7Comments  路  Source: FriendsOfSymfony/FOSUserBundle

I've googled so many other options, and there are so many similar stack overflow questions that I've looked at, but they all dealt with outdated versions of Symfony or FOSUserBundle... It doesn't help that the FOSUserBundle documentation doesn't exactly cover how to add custom fields to the Profile page, only the registration page.

So how do I make custom fields I've added to the User class show up in the user's profile page? I've tried pretty much all other stack overflow attempts.

Here's my services.yml:

services:
    app.profile.form.type:
        class: AppBundle\Form\ProfileFormType
        tags:
            - { name: form.type, alias: app_user_profile }

Here's my config.yml:

fos_user:
    profile:
        form:
            type: AppBundle\Form\ProfileFormType

And just one iteration of many of my Profile class:

namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ProfileFormType extends AbstractType
{
    public function buildUserForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('pokemon');
    }

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

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

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

}

Most helpful comment

The method of AbstractType to customize fields is buildForm, not buildUserForm

All 7 comments

The method of AbstractType to customize fields is buildForm, not buildUserForm

Well the ProfileFormType.php code I put up was just one of many iterations -- I tried it with buildForm and that didn't work either.

Same problem, resolved with the Stof comment. Thank you ;)

@dwangus, I think your problem is in the config.yml. Your namespace for your custom class is AppBundle\Form\Type and you call AppBundle\Form\ProfileFormType instead of AppBundle\Form\Type\ProfileFormType

@Zubis Do you think you could upload your code? I fixed the paths called, but it still doesn't work and it doesn't show up at localhost:8000/profile :(

See comments above.

Hello I have something like this. you need to create a fom called profileFormType.php with your fosuser entity as your data_class
profile

That is a screenshot of how it is going to look like

Was this page helpful?
0 / 5 - 0 ratings