From 485666fb97f6ffa3c75f33295f4be15ecf791815 Mon Sep 17 00:00:00 2001 From: Jasper Smet Date: Sat, 24 Oct 2026 14:01:48 +0200 Subject: [PATCH] Correct the validation provider event order Refs cakephp/cakephp#19707. --- docs/en/appendices/6-0-migration-guide.md | 4 ++++ docs/en/orm/table-objects.md | 6 ++++-- docs/en/orm/validation.md | 5 +++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/en/appendices/6-0-migration-guide.md b/docs/en/appendices/6-0-migration-guide.md index 6832c801e6..d1a76099c2 100644 --- a/docs/en/appendices/6-0-migration-guide.md +++ b/docs/en/appendices/6-0-migration-guide.md @@ -18,6 +18,10 @@ deprecation warnings. - `Cake\Event\Event::getSubject()` can now return `null` if the event has no subject instead of throwing an exception. +- `Model.buildValidator` is now dispatched before the named validation method, + allowing listeners to register providers used by `Validator::add()`. Listeners + that inspect rules added by `validationDefault()` must account for this order. + ## Breaking Changes ### Renamed Methods diff --git a/docs/en/orm/table-objects.md b/docs/en/orm/table-objects.md index 7d3c0fcc3d..041df983d4 100644 --- a/docs/en/orm/table-objects.md +++ b/docs/en/orm/table-objects.md @@ -282,8 +282,10 @@ been replaced with the [Map Reduce](../orm/retrieving-data-and-resultsets#map-re `method` Cake\\ORM\\Table::**buildValidator**(EventInterface $event, Validator $validator, $name): void -The `Model.buildValidator` event is fired when `$name` validator is created. -Behaviors, can use this hook to add in validation methods. +The `Model.buildValidator` event is fired when the `$name` validator is created, +before the table's `validationDefault()` or other named validation method runs. +Behaviors and other listeners can register providers here so that their rules +are available when the validation method calls `Validator::add()`. ### buildRules diff --git a/docs/en/orm/validation.md b/docs/en/orm/validation.md index 87a1dcc8d8..24e7e3af45 100644 --- a/docs/en/orm/validation.md +++ b/docs/en/orm/validation.md @@ -35,8 +35,9 @@ When building an entity with validation enabled the following occurs: 1. The validator object is created. 2. The `table` and `default` validation provider are attached. -3. The named validation method is invoked. For example `validationDefault`. -4. The `Model.buildValidator` event will be triggered. +3. The `Model.buildValidator` event is triggered, allowing behaviors and other + listeners to register validation providers. +4. The named validation method is invoked. For example `validationDefault`. 5. Request data will be validated. 6. Request data will be type-cast into types that match the column types. 7. Errors will be set into the entity.