From 5dbab03b2d407d7665a4469d5e89a514afb1dcea Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 23 Aug 2022 14:08:28 +0200 Subject: [PATCH] add missing attributes code block --- reference/constraints/Collection.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/reference/constraints/Collection.rst b/reference/constraints/Collection.rst index e708511d309..62595aef75e 100644 --- a/reference/constraints/Collection.rst +++ b/reference/constraints/Collection.rst @@ -239,6 +239,29 @@ you can do the following: protected $profileData = ['personal_email' => 'email@example.com']; } + .. code-block:: php-attributes + + // src/Entity/Author.php + namespace App\Entity; + + use Symfony\Component\Validator\Constraints as Assert; + + class Author + { + #[Assert\Collection( + fields: [ + 'personal_email' => new Assert\Required([ + new Assert\NotBlank, + new Assert\Email, + ]), + 'alternate_email' => new Assert\Optional( + new Assert\Email + ), + ], + )] + protected $profileData = ['personal_email' => 'email@example.com']; + } + .. code-block:: yaml # config/validator/validation.yaml