symfony: [Validation] Doesn't override properly

I want to override the FOSUserBundle validation.xml so I created a new bundle which extends the FOSUserBundle:

public function getParent()
{
    return 'FOSUserBundle';
}

But the validation.xml of the FOSUserBundle is still loaded.

I think the Validation component should respect the bundle inheritance.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

I don’t need username for registration and my solution is:

Set your own validation groups for FOSUserBundle registration and profile (eventualy for Group) form in config:

fos_user:
    registration:
        form:
            type:  app_frontend_registration #my own registration form
            validation_groups: [ my_registration, Default ]
    profile:
        form:
            type:  app_frontend_profile
            validation_groups: [ my_profile, Default]

Completly redefine validations for FOSUserBundle registration with own registrations groups without username:

FOS\UserBundle\Model\User:
    properties:
        email:
            - NotBlank:
                message: fos_user.email.blank
                groups: [ "my_registration", "my_profile" ]
            - Length:
                min: 2
                minMessage: fos_user.email.short
                max: 255
                maxMessage: fos_user.email.long
                groups: [ "my_registration", "ResetPassword" ]
            - Email:
                message: fos_user.email.invalid
                groups: [ "my_registration", "my_profile" ]             
        plainPassword:
            - NotBlank:
                message: fos_user.email.blank
                groups: [ "my_registration", "ResetPassword", "ChangePassword" ]
            - Length:
                min: 2
                minMessage: fos_user.password.blank                
                groups: [ "my_registration", "my_profile", "ResetPassword", "ChangePassword"]

FOS\UserBundle\Model\Group:
    properties:
        name:
            - NotBlank:
                message: fos_user.group.blank
                groups: [ "my_registration" ]
            - Length:
                min: 2
                minMessage: fos_user.group.short
                max: 255
                maxMessage: fos_user.group.long
                groups: [ "my_registration" ]

FOS\UserBundle\Propel\User:
    properties:
        email:
            - NotBlank:
                message: fos_user.email.blank
                groups: [ "my_registration", "my_profile" ]
            - Length:
                min: 2
                minMessage: fos_user.email.short
                max: 255
                maxMessage: fos_user.email.long
                groups: [ "my_registration", "ResetPassword" ]
            - Email:
                message: fos_user.email.invalid
                groups: [ "my_registration", "my_profile" ]

        plainPassword:
            - NotBlank:
                message: fos_user.email.blank
                groups: [ "my_registration", "ResetPassword", "ChangePassword" ]
            - Length:
                min: 2
                minMessage: fos_user.password.blank                
                groups: [ "my_registration", "my_profile", "ResetPassword", "ChangePassword"]


FOS\UserBundle\Propel\Group:
    properties:
        name:
            - NotBlank:
                message: fos_user.group.blank
                groups: [ "my_registration" ]
            - Length:
                min: 2
                minMessage: fos_user.group.short
                max: 255
                maxMessage: fos_user.group.long
                groups: [ "my_registration" ]

It works fine for me.

the validation component will load the validation.xml file for every bundle (if the file exists). And each bundle can provide validation rules for the classes it wants (AcmeDemoBundle could provide rules for classes of FOSUserBundle, FrameworkBundle and AcmeHelloBundle for instance). There is no mapping between the XML file in which rules are defined and the class.