Skip to content

Commit a4594d1

Browse files
authored
Merge pull request #8051 from cakephp/5.next-context-validation
Have entity part of context for validation
1 parent 29e496d commit a4594d1

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

en/appendices/5-3-migration-guide.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Database
2222
- ``Query::with()`` now accepts an array of expressions to align with other query clauses. This also
2323
allows clearing the expressions with an empty array.
2424

25+
Validation
26+
----------
27+
28+
- The signature of ``Validator::validate(array $data, bool $newRecord = true, array $context = [])`` has now a additional third parameter ``$context``.
29+
It can be used to pass necessary context into the validation when marshalling.
30+
2531
View
2632
----
2733

@@ -118,6 +124,8 @@ Validation
118124
----------
119125

120126
- ``ipOrRange()`` validation has has been added to check for an IP or a range (subnet).
127+
- When validating within CakePHP marshalling context, the entity will be passed into the ``context`` argument for use inside custom validation rules.
128+
This can be useful when patching partially and then needing to get that data from the entity instead of the passed data.
121129

122130
TestSuite
123131
---------

en/core-libraries/validation.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,17 @@ containing data related to the validation process:
195195
need to create complex rules by calling multiple providers.
196196
- **newRecord**: Whether the validation call is for a new record or
197197
a preexisting one.
198+
- **entity**: The entity being validated if provided to ``validate()``.
198199

199200
Closures should return boolean true if the validation passes. If it fails,
200201
return boolean false or for a custom error message return a string, see the
201202
:ref:`Conditional/Dynamic Error Messages <dynamic_validation_error_messages>`
202203
section for further details.
203204

205+
.. versionchanged:: 5.3.0
206+
The ``entity`` key was added to validation context.
207+
208+
204209
.. _dynamic_validation_error_messages:
205210

206211
Conditional/Dynamic Error Messages

0 commit comments

Comments
 (0)