File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -210,7 +210,7 @@ constraint.
210
210
}
211
211
}
212
212
213
- If the callback is stored in a different class and is static, for example ``AppBundle\Entity\Genre ``,
213
+ If the callback is defined in a different class and is static, for example ``AppBundle\Entity\Genre ``,
214
214
you can pass the class name and the method as an array.
215
215
216
216
.. configuration-block ::
@@ -279,6 +279,35 @@ you can pass the class name and the method as an array.
279
279
}
280
280
}
281
281
282
+ Supplying the Choices from an Array Constant
283
+ --------------------------------------------
284
+
285
+ You can also directly provide a constant containing an array to the ``choices `` option in the annotation::
286
+
287
+ // src/AppBundle/Entity/Author.php
288
+ namespace AppBundle\Entity;
289
+
290
+ use Symfony\Component\Validator\Constraints as Assert;
291
+
292
+ class Author
293
+ {
294
+ const GENRES = ['action', 'comedy'];
295
+
296
+ /**
297
+ * @Assert\Choice(choices=Author::GENRES)
298
+ */
299
+ protected $genre;
300
+ }
301
+
302
+ .. warning ::
303
+
304
+ The constant in the option is used without quotes.
305
+
306
+ .. note ::
307
+
308
+ If the constant is defined in a different class, you can pass the fully qualified class name.
309
+
310
+
282
311
Available Options
283
312
-----------------
284
313
You can’t perform that action at this time.
0 commit comments