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

Harmonize Form/Entity Validation #1152

Closed
solverat opened this issue Oct 30, 2019 · 1 comment
Closed

Harmonize Form/Entity Validation #1152

solverat opened this issue Oct 30, 2019 · 1 comment

Comments

@solverat
Copy link
Contributor

Q A
Bug report? sort of
Feature request? sort of
BC Break report? no
RFC? yes

There are a lot of validation / constraint stuff in coreshop and sometimes there are some annoying mismatches.

For example, I want to improve the customers password field constraints in the whole ecosystem. I'm starting with the customer entity:

CoreShop\Component\Customer\Model\Customer:
    getters:
        password:
            - Length: { min: 8, minMessage: 'foo.bar.customer.password.min' }

Done. From now on, my registration form validates the password field against 8 characters.
But now I also need to add a form extension to ChangePasswordType and ResetPasswordType because they don't validate new data on entity level. This is pure pain.


Only if a form contains a corresponding data class, the validation gets dispatched automatically. So adding a validation before saving a customer could solve this:

$this->get('validator')->validate($customer)

Mission

Find a consistent way for all forms and entities, so we can easily modify or extend validations:

  • Custom coreshop form / entity validation configuration for example
  • Add validation(Via Validator) in every action if no form data class is available for example
@dpfaffenbauer
Copy link
Member

You are talking about very specific form-types. ChangePasswordType and ResetPasswordType are some sort of special forms and a Customer constraint will never work for them.

ResetPasswordType

Doesn't have a customer, we could introduce a new DTO like with AddToCart to add validations to that model.

ChangePasswordType

Does have a relation to a customer, but we also need to validate for the current password, which we do with a constraint already. If we change that to a custom DTO model (eg. ChangePasswordRequest) we could also make the configuration with YML.

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

No branches or pull requests

2 participants