@@ -89,19 +89,18 @@ but here's a short example::
8989
9090 use Symfony\Component\Form\Extension\Core\Type\TextType;
9191 use Symfony\Component\Form\FormBuilderInterface;
92- use Symfony\Component\Validator\Constraints\Length;
93- use Symfony\Component\Validator\Constraints\NotBlank;
92+ use Symfony\Component\Validator\Constraints as Assert;
9493
9594 public function buildForm(FormBuilderInterface $builder, array $options): void
9695 {
9796 $builder
9897 ->add('firstName', TextType::class, [
99- 'constraints' => new Length(min: 3),
98+ 'constraints' => new Assert\ Length(min: 3),
10099 ])
101100 ->add('lastName', TextType::class, [
102101 'constraints' => [
103- new NotBlank(),
104- new Length(min: 3),
102+ new Assert\ NotBlank(),
103+ new Assert\ Length(min: 3),
105104 ],
106105 ])
107106 ;
@@ -113,7 +112,9 @@ but here's a short example::
113112 ``Default `` group when creating the form, or set the correct group on
114113 the constraint you are adding::
115114
116- new NotBlank(['groups' => ['create', 'update']]);
115+ use Symfony\Component\Validator\Constraints as Assert;
116+
117+ new Assert\NotBlank(groups: ['create', 'update']);
117118
118119.. tip ::
119120
@@ -137,9 +138,7 @@ This can be done by setting the ``constraints`` option in the
137138 use Symfony\Component\Form\Extension\Core\Type\TextType;
138139 use Symfony\Component\Form\FormBuilderInterface;
139140 use Symfony\Component\OptionsResolver\OptionsResolver;
140- use Symfony\Component\Validator\Constraints\Collection;
141- use Symfony\Component\Validator\Constraints\Length;
142- use Symfony\Component\Validator\Constraints\NotBlank;
141+ use Symfony\Component\Validator\Constraints as Assert;
143142
144143 public function buildForm(FormBuilderInterface $builder, array $options): void
145144 {
@@ -152,11 +151,11 @@ This can be done by setting the ``constraints`` option in the
152151 {
153152 $resolver->setDefaults([
154153 'data_class' => null,
155- 'constraints' => new Collection([
156- 'firstName' => new Length(min: 3),
154+ 'constraints' => new Assert\ Collection([
155+ 'firstName' => new Assert\ Length(min: 3),
157156 'lastName' => [
158- new NotBlank(),
159- new Length(min: 3),
157+ new Assert\ NotBlank(),
158+ new Assert\ Length(min: 3),
160159 ],
161160 ]),
162161 ]);
@@ -165,12 +164,14 @@ This can be done by setting the ``constraints`` option in the
165164This means you can also do this when using the ``createFormBuilder() `` method
166165in your controller::
167166
167+ use Symfony\Component\Validator\Constraints as Assert;
168+
168169 $form = $this->createFormBuilder($defaultData, [
169170 'constraints' => [
170- 'firstName' => new Length([' min' => 3] ),
171+ 'firstName' => new Assert\ Length(min: 3 ),
171172 'lastName' => [
172- new NotBlank(),
173- new Length([' min' => 3] ),
173+ new Assert\ NotBlank(),
174+ new Assert\ Length(min: 3 ),
174175 ],
175176 ],
176177 ])
0 commit comments