I have my own User Class, wich inherits Sonata's BaseUser (Sonata\UserBundle\Entity\BaseUser)
.
My problem: If I try to create a user from sonata admin using an existing email, I get the following exception:
"Failed to create object: Application\Sonata\UserBundle\Entity\User" SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint DETAIL: Key (email_canonical)=(test@test.com) already exists.
I tried to use as suggested in some documentations & tickets UniqueEntity using the proper use statements, but to no avail.
I use the UniqueEntity annotation on other entities with sonata admin without a problem, and I'm getting a nice message inside the form which notifies the user that there is already an entity with that name/title instead of the exception. But for the User entity it simply does not work the same way.
This is how I registered sonata user bundle in AppKernel:
new Application\Sonata\UserBundle\ApplicationSonataUserBundle('FOSUserBundle')
extending FOSUserBundle
use statements in custom User entity (generated by EasyExtends bundle, just that I've added some custom columns & one to many relations with other entities like ex: Project):
namespace Application\Sonata\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
and this is the annotation for the user class:
/**
* User
*
* @ORM\Table(name="fos_users")
* @ORM\Entity
* @UniqueEntity("username")
* @UniqueEntity("username_canonical")
* @UniqueEntity("email")
* @UniqueEntity("email_canonical")
*/
this is my config for sonata_user:
sonata_user:
security_acl: true
manager_type: orm
class:
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
this is the config for fos_user:
fos_user:
db_driver: orm
firewall_name: admin, user
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
user_manager: sonata.user.orm.user_manager
I'm using a custom admin class
parameters:
#use custom user admin class
sonata.user.admin.user.class: Application\Sonata\UserBundle\Admin\Model\UserAdmin
(I've also tried with the default admin class)
this is my sonata admin configuration:
sonata_admin: security: handler: sonata.admin.security.handler.acl title: My App templates: layout: CoreBundle:Admin:standard_layout.html.twig
I have also tried to override validation.yml/validation.xml file with my own validation rules ... but they're ignored or something like that ...
I am out of ideas. I would be very grateful if you could help me.