Skip to content

Commit 13997c7

Browse files
committed
minor #10103 Documented the findByCodes() validation method (javiereguiluz)
This PR was merged into the 3.4 branch. Discussion ---------- Documented the findByCodes() validation method Fixes #7786. Commits ------- 5cd7605 Documented the findByCodes() validation method
2 parents 26493f3 + 5cd7605 commit 13997c7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/validator.rst

+13-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ characters long::
5353
}
5454
}
5555

56-
The validator returns the list of violations.
56+
The ``validate()`` method returns the list of violations as an object that
57+
implements :class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`.
58+
If you have lots of validation errors, you can filter them by error code::
59+
60+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
61+
62+
$violations = $validator->validate(...);
63+
if (count($violations->findByCodes(UniqueEntity::NOT_UNIQUE_ERROR))) {
64+
// handle this specific error (display some message, send an email, etc.)
65+
}
66+
67+
.. versionadded:: 3.3
68+
The ``findByCodes()`` method was introduced in Symfony 3.3.
5769

5870
Retrieving a Validator Instance
5971
-------------------------------

0 commit comments

Comments
 (0)