@@ -34,7 +34,7 @@ If your valid choice list is simple, you can pass them in directly via the
3434 {
3535 public const GENRES = ['fiction', 'non-fiction'];
3636
37- #[Assert\Choice(['New York', 'Berlin', 'Tokyo'])]
37+ #[Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])]
3838 protected string $city;
3939
4040 #[Assert\Choice(choices: Author::GENRES, message: 'Choose a valid genre.')]
@@ -47,7 +47,8 @@ If your valid choice list is simple, you can pass them in directly via the
4747 App\Entity\Author :
4848 properties :
4949 city :
50- - Choice : [New York, Berlin, Tokyo]
50+ - Choice :
51+ choices : [New York, Berlin, Tokyo]
5152 genre :
5253 - Choice :
5354 choices : [fiction, non-fiction]
@@ -64,9 +65,11 @@ If your valid choice list is simple, you can pass them in directly via the
6465 <class name =" App\Entity\Author" >
6566 <property name =" city" >
6667 <constraint name =" Choice" >
67- <value >New York</value >
68- <value >Berlin</value >
69- <value >Tokyo</value >
68+ <option name =" choices" >
69+ <value >New York</value >
70+ <value >Berlin</value >
71+ <value >Tokyo</value >
72+ </option >
7073 </constraint >
7174 </property >
7275 <property name =" genre" >
@@ -97,7 +100,7 @@ If your valid choice list is simple, you can pass them in directly via the
97100 {
98101 $metadata->addPropertyConstraint(
99102 'city',
100- new Assert\Choice(['New York', 'Berlin', 'Tokyo'])
103+ new Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])
101104 );
102105
103106 $metadata->addPropertyConstraint('genre', new Assert\Choice(
@@ -107,6 +110,12 @@ If your valid choice list is simple, you can pass them in directly via the
107110 }
108111 }
109112
113+ .. deprecated :: 7.4
114+
115+ Passing an array of choices as the first argument of the ``Choice `` constraint
116+ is deprecated and will stop working in Symfony 8.0. Instead, pass the choices
117+ using the ``choices: `` named argument.
118+
110119Supplying the Choices with a Callback Function
111120----------------------------------------------
112121
0 commit comments