@@ -34,9 +34,9 @@ short) defined somewhere in your application. This enum has to be of type
3434
3535 enum TextAlign: string
3636 {
37- case Left = 'Left/Start aligned';
38- case Center = 'Center/Middle aligned';
39- case Right = 'Right/End aligned';
37+ case Left = 'Left aligned';
38+ case Center = 'Center aligned';
39+ case Right = 'Right aligned';
4040 }
4141
4242Instead of using the values of the enumeration in a ``choices `` option, the
@@ -52,6 +52,20 @@ This will display a ``<select>`` tag with the three possible values defined in
5252the ``TextAlign `` enum. Use the `expanded `_ and `multiple `_ options to display
5353these values as ``<input type="checkbox"> `` or ``<input type="radio"> ``.
5454
55+ The label displayed in the ``<option> `` elements of the ``<select> `` is the enum
56+ name. PHP defines some strict rules for these names (e.g. they can't contain
57+ dots or spaces). If you need more flexibility for these labels, use the
58+ ``choice_label `` option and define a function that returns the custom label::
59+
60+ ->add('textAlign', EnumType::class, [
61+ 'class' => TextAlign::class,
62+ 'choice_label' => match ($choice) {
63+ TextAlign::Left => 'text_align.left.label',
64+ TextAlign::Center => 'text_align.center.label',
65+ TextAlign::Right => 'text_align.right.label',
66+ },
67+ ]);
68+
5569Field Options
5670-------------
5771
0 commit comments