@@ -34,9 +34,9 @@ short) defined somewhere in your application. This enum has to be of type
34
34
35
35
enum TextAlign: string
36
36
{
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';
40
40
}
41
41
42
42
Instead 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
52
52
the ``TextAlign `` enum. Use the `expanded `_ and `multiple `_ options to display
53
53
these values as ``<input type="checkbox"> `` or ``<input type="radio"> ``.
54
54
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
+
55
69
Field Options
56
70
-------------
57
71
0 commit comments