Skip to content

Commit 50a78d1

Browse files
committed
Merge branch '3.4' into 4.2
* 3.4: [Validator] Explained how to use array constant in annotation
2 parents 32e7bfc + 687d345 commit 50a78d1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

reference/constraints/Choice.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ If your valid choice list is simple, you can pass them in directly via the
4343
4444
class Author
4545
{
46+
const GENRES = ['fiction', 'non-fiction'];
47+
4648
/**
4749
* @Assert\Choice({"New York", "Berlin", "Tokyo"})
4850
*/
4951
protected $city;
5052
5153
/**
52-
* @Assert\Choice(choices={"fiction", "non-fiction"}, message="Choose a valid genre.")
54+
* You can also directly provide an array constant to the "choices" option in the annotation
55+
*
56+
* @Assert\Choice(choices=Author::GENRES, message="Choose a valid genre.")
5357
*/
5458
protected $genre;
5559
}
@@ -203,7 +207,7 @@ constraint.
203207
}
204208
}
205209
206-
If the callback is stored in a different class and is static, for example ``App\Entity\Genre``,
210+
If the callback is defined in a different class and is static, for example ``App\Entity\Genre``,
207211
you can pass the class name and the method as an array.
208212

209213
.. configuration-block::

0 commit comments

Comments
 (0)