Reputation: 7739
I would like set email to not required on my User entities. How do what ? I've searched in FOSUserBundle/config/ but i don't find any "required" parameter about email.
Upvotes: 5
Views: 3574
Reputation: 1000
Following Tib's answer, here is the way I did it. It's working fine :
/**
* User
*
* @ORM\Table(name="user")
* @ORM\Entity
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email", length=255, unique=false, nullable=true)),
* @ORM\AttributeOverride(name="emailCanonical", column=@ORM\Column(type="string", name="email_canonical", length=255, unique=false, nullable=true))
* })
*/
class User extends BaseUser {
// ...
}
The previous solution is easy to implement and was working fine, but after updating Symfony to version 2.1.8 and without changing anything in my app, generating entities failes throwing a Doctrine mapping exception (Invalid field override ...)
In spite of loosing a lot of time trying to solve that issue, I was just stucked.
Then I finally realized that FOSUserBundle provides lot of features I don't use, but doesn't really fit my needs, which are quite basic.
I need to disable email requirement because my app user management is "software like" : no registration, no email sending, no profil, user and roles managed only by admin, etc...
I was adapting a tool not designed for my needs. So I decided to make my own implementation of Symfony security.
It is a little more work, but it's not very difficult and the result is far better and more flexible than adapting FOSUserBundle. Of course, for a "classic" website or web app, FOSUserBundle is the best.
If you are in this case too, I suggest you to do so. Here is the doc to begin : Security in the Book and Security in the CookBook
I hope this can help you.
Sorry for my poor english, I hope it is intelligible
Upvotes: 7
Reputation: 2631
Check this PR https://github.com/doctrine/orm-documentation/pull/117/files and look at @AttributeOverrides
Upvotes: 1
Reputation: 1702
You need to override following methods in the entity User.
class User extends BaseUser // inheritance from fos
{
/**
* @var string
* @ORM\column(type="string", name="email", length=255, unique=true, )
* @Assert\Email(
* checkMX = true
* )*/
protected $email
}
}
You need to change Table definition to:
class User extends BaseUser // inheritance from fosUserBundle
{
/**
* @var string
* @ORM\column(type="string", name="email", length=255, unique=false, nullable=true )
*/
protected $email
}
}
Same thing is needed for emailCanonical attribute.
If that not pass. You will need to copy entire model from FOS into your bundle and then change it as I wrote.
check the doc: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.2.0/Resources/doc/doctrine.md
Regards Max
Upvotes: -4