Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Validation] Doesn't override properly #3224

Closed
ruudk opened this issue Jan 30, 2012 · 20 comments
Closed

[Validation] Doesn't override properly #3224

ruudk opened this issue Jan 30, 2012 · 20 comments

Comments

@ruudk
Copy link
Contributor

ruudk commented Jan 30, 2012

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.

@stof
Copy link
Member

stof commented Jan 30, 2012

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.

@ruudk
Copy link
Contributor Author

ruudk commented Jan 31, 2012

Ok, I understand. But the problem is that the FOSUserBundle has validation setup for

<class name="FOS\UserBundle\Model\User">

My UserModel extends this class (this is necessary for FOSUserBundle to work).

So in my validation.xml I want to setup my own validation rules:

<class name="Acme\UserBundle\Entity\User">

But the rules of FOS\UserBundle\Model\User are still used. Is there a way to say: "do not inherit FOS\UserBundle\Model\User validation.xml"?

Or is the only way to create your own groups? And use them? Instead of the default FOS groups (Registration, Profile, etc)

@stof
Copy link
Member

stof commented Jan 31, 2012

use different validation groups for this. it is one of their use case.

@webmozart
Copy link
Contributor

Please post the issue in the appropriate repository: http://github.com/FriendsOfSymfony/FOSUserBundle

See also #2605 and #1021

@umpirsky
Copy link
Contributor

umpirsky commented Nov 8, 2012

@stof I tried to achieve this with validation groups, but it didn't work.

@mvrhov
Copy link

mvrhov commented Nov 8, 2012

The other thing is that groups are annoying. Just because I cannot override the validatiors in my bundle even though the documentation states I can do that!. I have to come up with a new creative validation group names which is quite annoying.

@umpirsky
Copy link
Contributor

umpirsky commented Nov 9, 2012

I think this bug should be reopened.

@mvrhov
Copy link

mvrhov commented Feb 1, 2013

Can we have this reopened because creating a new groups and comming up with a proper names for them just because we cannot override the validation constraints is beyond annoying.

@rayrigam
Copy link

What is the standard way to tell the FOSUserBundle Registration Form NOT to use the "registration" (or any other) Validation Group? I'm trying to use my own validation.xml (which I included in my bundle, but applies to the User class in the FOSUserBundle), and it works except that the error message for unique contraint for the username and email is shown twice as both the validation in my bundle (which is not in a validation group) and the validation in the FOSUserBundle, which is in the "registration" validation group, are applied.

@petrslavicek
Copy link

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.

@yakom
Copy link

yakom commented Aug 26, 2013

@petrslavicek 👍 Thank you!

@wouterj
Copy link
Member

wouterj commented Sep 12, 2013

So, I order to override validation of a 3th party bundle, that bundle needs to provide some configuration for the validation groups? Seems somewhat wrong to me...

@yakom
Copy link

yakom commented Sep 12, 2013

@wouterj You can override validation with bundle inheritance, just as described in manual. FOSUserBundle, on the other hand, gives you a possibility to override validation without the inheritance.

@wouterj
Copy link
Member

wouterj commented Sep 12, 2013

@yakom you can't override it. The validation file of the parent bundle is still loaded.

@bdecarne
Copy link

bdecarne commented Nov 6, 2013

:+1 with WouterJ. All these validation group solutions seems to be a hack.

@joschi127
Copy link

👍 Would be really useful being able to easily override annotations.

Something like

/** 
 * @Assert:NoInheritance()
 */

as suggested under #1021 would be really helpful.

Use case for us:
Just think of a default implementation where the subject field has Assert\NotBlank() but in a customized version (used for some other customer) blank values should be allowed. Using validation groups is much more complicated and seems to be a hack.

@rickard2
Copy link

+1

Would also like to override annotations for specific installations. My use case is exactly the same as @joschi127

Will use validation groups for now.

@webmozart
Copy link
Contributor

I'm closing this as a duplicate of #5953 which has a better problem description.

@gondo
Copy link
Contributor

gondo commented Oct 7, 2014

+1

1 similar comment
@VanVan
Copy link

VanVan commented Oct 21, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests