From 5cd7605d0911aa5183f2fc0966eeebd77cc07a61 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 20 Jul 2018 10:22:59 +0200 Subject: [PATCH] Documented the findByCodes() validation method --- components/validator.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/validator.rst b/components/validator.rst index 3c4c745bc5a..59afb7f963d 100644 --- a/components/validator.rst +++ b/components/validator.rst @@ -53,7 +53,19 @@ characters long:: } } -The validator returns the list of violations. +The ``validate()`` method returns the list of violations as an object that +implements :class:`Symfony\\Component\\Validator\\ConstraintViolationListInterface`. +If you have lots of validation errors, you can filter them by error code:: + + use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; + + $violations = $validator->validate(...); + if (count($violations->findByCodes(UniqueEntity::NOT_UNIQUE_ERROR))) { + // handle this specific error (display some message, send an email, etc.) + } + +.. versionadded:: 3.3 + The ``findByCodes()`` method was introduced in Symfony 3.3. Retrieving a Validator Instance -------------------------------