2
votes

I am trying to use Sonata User Bundle and extend the user entity to add some extra relations. I created my own ApplicationSonataUserBundle child bundle as documented here: http://sonata-project.org/bundles/user/master/doc/reference/installation.html Everything works fine except for form validation. I have looked at: http://symfony.com/doc/current/cookbook/bundles/override.html#override-validation

If I understand it correctly I need to do this only if I want to override some constraints. But I would like my entity to inherit all the constraints that are set in FOS User Bundle (which is extended by Sonata User Bundle, which is extended by my own ApplicationSonataUserBundle )

Still when I print my registration form the constraints seem to be ignored.... no unique check on emailCanonical etc, password lengths or anything.

My solution is to create a whole new validation.xml for my extended entity and place it in my ApplicationSonataUserBundle. Is this correct or is there any other way i can inherit the constraints from the extended Application\Sonata\UserBundle\Entity\User that supposedly inherits the constraints from FOS\UserBundle\Model\User ?

TIA.

1

1 Answers

0
votes

I think the idea is that you should assign your new rules to a new validation group, then use the config.yml file to add your validation group to the defaults, e.g.

sonata_user:
    profile:
        form:
            validation_groups:  [CustomGroup, Profile, Default]

However, I can't get this to work (which is why I found this thread)... let me know if you have better luck!

By the way, I have posted my own problems with this as a separate question: Adding customised validation rules to SonataUserBundle

If there's an answer there I'll try to update it here too.