@@ -34,7 +34,7 @@ If your valid choice list is simple, you can pass them in directly via the
34
34
{
35
35
public const GENRES = ['fiction', 'non-fiction'];
36
36
37
- #[Assert\Choice(['New York', 'Berlin', 'Tokyo'])]
37
+ #[Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])]
38
38
protected string $city;
39
39
40
40
#[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
47
47
App\Entity\Author :
48
48
properties :
49
49
city :
50
- - Choice : [New York, Berlin, Tokyo]
50
+ - Choice :
51
+ choices : [New York, Berlin, Tokyo]
51
52
genre :
52
53
- Choice :
53
54
choices : [fiction, non-fiction]
@@ -64,9 +65,11 @@ If your valid choice list is simple, you can pass them in directly via the
64
65
<class name =" App\Entity\Author" >
65
66
<property name =" city" >
66
67
<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 >
70
73
</constraint >
71
74
</property >
72
75
<property name =" genre" >
@@ -97,7 +100,7 @@ If your valid choice list is simple, you can pass them in directly via the
97
100
{
98
101
$metadata->addPropertyConstraint(
99
102
'city',
100
- new Assert\Choice(['New York', 'Berlin', 'Tokyo'])
103
+ new Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])
101
104
);
102
105
103
106
$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
107
110
}
108
111
}
109
112
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
+
110
119
Supplying the Choices with a Callback Function
111
120
----------------------------------------------
112
121
0 commit comments