Skip to content

Have entity part of context for validation #8051

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

Open
wants to merge 3 commits into
base: 5.next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions en/appendices/5-3-migration-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----

Expand Down Expand Up @@ -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
---------
Expand Down
5 changes: 5 additions & 0 deletions en/core-libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dynamic_validation_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
Expand Down
Loading