Skip to content

Documented the findByCodes() validation method #10103

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

Merged
merged 1 commit into from
Jul 20, 2018
Merged
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
14 changes: 13 additions & 1 deletion components/validator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------
Expand Down