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

[5.x] Update our custom string based rules to class based rules #9785

Merged
merged 27 commits into from
Mar 28, 2024

Conversation

jesseleite
Copy link
Member

@jesseleite jesseleite commented Mar 25, 2024

Validation rule changes

As an extension to #9778 and #9780, this PR refactors our old custom validation rule classes in the Statamic\Validation namespace, to proper Laravel ValidationRule implementations within Statamic\Rules, and also removes string based

Validation builder changes

As for the custom rules we had defined in our old ValidationServiceProvider, we now explicitly define which custom rules get added to the validation builder in our Rules.js object:

CleanShot 2024-03-27 at 16 08 33

It makes sense for people to add extra unique validation rules in their own blueprints, but we don't think it ever made sense for unique_form_handle or code_fieldtype_rulers to appear in the builder UI, so these will no longer show 👌

Todo

  • Update ClassRuleParser and Fields\Validator to properly handle
    • {collection} style replacements
    • null values
    • true / false booleans
  • Move and update
    • UniqueEntryValue rule
      • Should also be accessible to users in validation builder UI
    • UniqueTermValue rule
      • Should also be accessible to users in validation builder UI
    • UniqueUserValue rule
      • Should also be accessible to users in validation builder UI
    • UniqueFormHandle rule
    • CodeFieldtypeRulers rule
  • Remove string based rule implementations (breaking)
    • Update script
      • Add test coverage
        • Note: Because string replacements on blueprints/fieldsets could get hairy, I made the script only attempt to replace strict single-quote surrounded rule usages. For example, if the user copied out of the docs, or saved the blueprint from the CP, they'll have single quotes around their rules. By making these replacements strict, the regex should never overzealously replace too much. If they're using these rules in a pipe-delimited rule string for some reason, we can mention that they'll need to use the new class-based rules in the upgrade guide.
  • Update tests
  • Update docs

@jesseleite jesseleite marked this pull request as ready for review March 27, 2024 23:24
@jesseleite jesseleite changed the title [5.x] Update our custom string based rules to conventional class based Laravel rules [5.x] Update our string based rules to class based rules Mar 27, 2024
@jesseleite jesseleite changed the title [5.x] Update our string based rules to class based rules [5.x] Update our custom string based rules to class based rules Mar 27, 2024
@jasonvarga jasonvarga merged commit 33461ff into master Mar 28, 2024
31 checks passed
@jasonvarga jasonvarga deleted the update-custom-rules-to-standard-laravel-rules branch March 28, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants