5

I am working on extending the FosUserBundle registration form. I need to remove/unset the username field (because I am using email as the username).

Is there a way to remove a field from a form that I am extending?

2 Answers 2

22

If you want to remove/unset some field in your form type which extends FOSUser one you can do something like:

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

    $builder->remove('username');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, someone suggested this yesterday on IRC. Unfortunately, while it does do exactly what I asked for, it does not change the validation array. More messing with the form is needed to fix the validation.
1

If you want to override constraint's attributes for example, you can do something like this :

<?php

namespace Acme\UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * User
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="username", column=@ORM\Column(nullable = true, unique = false ))
 *   })
 */
class User extends BaseUser {

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.