diff --git a/en/appendices/5-3-migration-guide.rst b/en/appendices/5-3-migration-guide.rst index 85978e974e..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 ---- @@ -106,6 +112,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 --------- 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