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

Add ValidationInterface to the DataObject class #11457

Closed
1 of 2 tasks
emteknetnz opened this issue Nov 6, 2024 · 6 comments
Closed
1 of 2 tasks

Add ValidationInterface to the DataObject class #11457

emteknetnz opened this issue Nov 6, 2024 · 6 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Nov 6, 2024

https://github.com/silverstripe/silverstripe-framework/blob/6/src/Core/Validation/ValidationInterface.php provides a standardised method signature for objects with a validate() method

So far this had been added to

  • DBField
  • FormField
  • FieldValidator (via the subclass FieldValidationInterface)

At very least it should be added to DataObject which already effectively implements it, just with loose typing.

If feasible within a reasonable amount of it, it should also be added to as many other objects that currently have a validate($validator) or validate(): bool, which will involve some level of refactoring

Acceptance criteria

  • ValidationInterface is added to DataObject
  • Any other validate() methods that can be easily refactored also implement ValidationInterface

Notes

Other validate() methods:

  • framework Form validationResult(): ValidationResult (could simply be renamed to validate())
  • framework Locales validate($locale): bool
  • framework IntlLocales validate($locale): bool
  • framework Embeddable validate(): bool
  • framework EmbedContainer validate(): bool
  • assets Upload_Validator validate(): bool
  • assets Upload validate(): bool
  • graphql - multiple validate(): void

Two lots of PRs:

A) Add ValidationInterface to DataObject
B) Rename Form::validationResult() to validate()

I've deemed changing the other method validate() methods with bool and void returns types as not worth the effort

A) Add ValidationInterface to DataObject - CM5 6.0

Kitchen Sink CI

^ test failures are existing - elemental - framework

PRs

B1) Rename Form::validationResult() to validate() - CMS 5

Kitchen Sink CI

PRs

Assign back to Steve to do merge-up and make PRs for CMS 6.0

B2) Rename Form::validationResult() to validate() - CMS 6.0

  • Add ValidationInterface to Form, and remove deprecated method

Kitchen Sink CI

^ Failing test is unrelated

PRs

@GuySartorelli
Copy link
Member

I've deemed changing the other method validate() methods with bool and void returns types as not worth the effort

Can you please explain what you mean by "the other method validate() methods with bool and void returns types" and your reasoning for why they're not worth the effort?

@GuySartorelli
Copy link
Member

@emteknetnz please respond to the above comment

@GuySartorelli
Copy link
Member

PRs merged. Reassigning to steve to respond to the above and to do B2

@emteknetnz
Copy link
Member Author

Can you please explain what you mean by "the other method validate() methods with bool and void returns types" and your reasoning for why they're not worth the effort?

In the "Notes" section in the description I listed what I think are all off the other validate() methods that don't return a ValidationResult.

DataObject::validate() and Form::validationResult() both return ValidationResult's already, so the amount of refactoring required in pretty minimal.

However all the other validate methods that don't return a ValidationResult require significantly more refactoring, and IMO it's not worth the effort at this stage given all the other things that need doing

@emteknetnz
Copy link
Member Author

Have double checked, cannot find any other instances of ->validationResult()

@GuySartorelli
Copy link
Member

PRs merged

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

2 participants