From fe24328d2c0e085073b9eb8f908135d3e8423879 Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 18 Jul 2025 17:04:46 +0200 Subject: [PATCH 1/3] Have entity part of context for validation --- en/appendices/5-3-migration-guide.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/en/appendices/5-3-migration-guide.rst b/en/appendices/5-3-migration-guide.rst index 85978e974e..18c33c409e 100644 --- a/en/appendices/5-3-migration-guide.rst +++ b/en/appendices/5-3-migration-guide.rst @@ -106,6 +106,8 @@ Validation ---------- - ``ipOrRange()`` validation has has been added to check for an IP or a range (subnet). +- When validating within CakePHP marshalling context, the entity will be passed into the ``context`` argument for use inside custom validation rules. + This can be useful when patching partially and then needing to get that data from the entity instead of the passed data. TestSuite --------- From 7e6801d9b1eea068c680b7762cc95c79fe90f233 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Fri, 18 Jul 2025 17:22:51 +0200 Subject: [PATCH 2/3] Update 5-3-migration-guide.rst --- en/appendices/5-3-migration-guide.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/en/appendices/5-3-migration-guide.rst b/en/appendices/5-3-migration-guide.rst index 18c33c409e..f06cff05aa 100644 --- a/en/appendices/5-3-migration-guide.rst +++ b/en/appendices/5-3-migration-guide.rst @@ -22,6 +22,12 @@ Database - ``Query::with()`` now accepts an array of expressions to align with other query clauses. This also allows clearing the expressions with an empty array. +Validation +---------- + +- The signature of ``Validator::validate(array $data, bool $newRecord = true, array $context = [])`` has now a additional third parameter ``$context``. + It can be used to pass necessary context into the validation when marshalling. + View ---- From 8f72a1a88181f02ad181fd7ca1ba78cf4457e174 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 21 Jul 2025 21:52:11 -0400 Subject: [PATCH 3/3] Add entity context to actual docs as well. --- en/core-libraries/validation.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/en/core-libraries/validation.rst b/en/core-libraries/validation.rst index 4e4b37ddca..f7c14db6d0 100644 --- a/en/core-libraries/validation.rst +++ b/en/core-libraries/validation.rst @@ -195,12 +195,17 @@ containing data related to the validation process: need to create complex rules by calling multiple providers. - **newRecord**: Whether the validation call is for a new record or a preexisting one. +- **entity**: The entity being validated if provided to ``validate()``. Closures should return boolean true if the validation passes. If it fails, return boolean false or for a custom error message return a string, see the :ref:`Conditional/Dynamic Error Messages ` section for further details. +.. versionchanged:: 5.3.0 + The ``entity`` key was added to validation context. + + .. _dynamic_validation_error_messages: Conditional/Dynamic Error Messages