8000 Documented the findByCodes() validation method · symfony/symfony-docs@5cd7605 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5cd7605

Browse files
committed
Documented the findByCodes() validation method
1 parent 26493f3 commit 5cd7605

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/validator.rst

Lines changed: 13 additions & 1 deletion
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)
0