@@ -43,7 +43,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
43
43
}
44
44
45
45
if ('single_text ' === $ options ['widget ' ]) {
46
- $ builder ->addViewTransformer (new DateTimeToStringTransformer ($ options ['data_timezone ' ], $ options ['user_timezone ' ], $ format ));
46
+ $ builder ->addViewTransformer (new DateTimeToStringTransformer (
47
+ $ options ['data_timezone ' ],
48
+ $ options ['user_timezone ' ],
49
+ $ format
50
+ ));
47
51
} else {
48
52
// Only pass a subset of the options to children
49
53
$ dateOptions = array_intersect_key ($ options , array_flip (array (
@@ -54,6 +58,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
54
58
'required ' ,
55
59
'translation_domain ' ,
56
60
)));
61
+
57
62
$ timeOptions = array_intersect_key ($ options , array_flip (array (
58
63
'hours ' ,
59
64
'minutes ' ,
@@ -64,21 +69,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
64
69
'translation_domain ' ,
65
70
)));
66
71
67
- // If `widget` is set, overwrite widget options from `date` and `time`
68
- if (isset ($ options ['widget ' ])) {
69
- $ dateOptions ['widget ' ] = $ options ['widget ' ];
70
- $ timeOptions ['widget ' ] = $ options ['widget ' ];
71
- } else {
72
- if (isset ($ options ['date_widget ' ])) {
73
- $ dateOptions ['widget ' ] = $ options ['date_widget ' ];
74
- }
75
-
76
- if (isset ($ options ['time_widget ' ])) {
77
- $ timeOptions ['widget ' ] = $ options ['time_widget ' ];
78
- }
72
+ if (null !== $ options ['date_widget ' ]) {
73
+ $ dateOptions ['widget ' ] = $ options ['date_widget ' ];
79
74
}
80
75
81
- if (isset ($ options ['date_format ' ])) {
76
+ if (null !== $ options ['time_widget ' ]) {
77
+ $ timeOptions ['widget ' ] = $ options ['time_widget ' ];
78
+ }
79
+
80
+ if (null !== $ options ['date_format ' ]) {
82
81
$ dateOptions ['format ' ] = $ options ['date_format ' ];
83
82
}
84
83
@@ -134,27 +133,28 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
134
133
return $ options ['widget ' ] !== 'single_text ' ;
135
134
};
136
135
136
+ // Defaults to the value of "widget"
137
+ $ dateWidget = function (Options $ options ) {
138
+ return $ options ['widget ' ];
139
+ };
140
+
141
+ // Defaults to the value of "widget"
142
+ $ timeWidget = function (Options $ options ) {
143
+ return $ options ['widget ' ];
144
+ };
145
+
137
146
$ resolver ->setDefaults (array (
138
147
'input ' => 'datetime ' ,
139
148
'data_timezone ' => null ,
140
149
'user_timezone ' => null ,
141
- 'date_widget ' => null ,
142
150
'date_format ' => null ,
143
- 'time_widget ' => null ,
144
- /* Defaults for date field */
145
- 'years ' => range (date ('Y ' ) - 5 , date ('Y ' ) + 5 ),
146
- 'months ' => range (1 , 12 ),
147
- 'days ' => range (1 , 31 ),
148
- /* Defaults for time field */
149
- 'hours ' => range (0 , 23 ),
150
- 'minutes ' => range (0 , 59 ),
151
- 'seconds ' => range (0 , 59 ),
151
+ 'widget ' => null ,
152
+ 'date_widget ' => $ dateWidget ,
153
+ 'time_widget ' => $ timeWidget ,
152
154
'with_seconds ' => false ,
153
155
// Don't modify \DateTime classes by reference, we treat
154
156
// them like immutable value objects
155
157
'by_reference ' => false ,
156
- // This will overwrite "widget" child options
157
- 'widget ' => null ,
158
158
// If initialized with a \DateTime object, FormType initializes
159
159
// this option to "\DateTime". Since the internal, normalized
160
160
// representation is not \DateTime, but an array, we need to unset
@@ -167,6 +167,12 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
167
167
// set in DateType and TimeType
168
168
$ resolver ->setOptional (array (
169
169
'empty_value ' ,
170
+ 'years ' ,
171
+ 'months ' ,
172
+ 'days ' ,
173
+ 'hours ' ,
174
+ 'minutes ' ,
175
+ 'seconds ' ,
170
176
));
171
177
172
178
$ resolver ->setAllowedValues (array (
0 commit comments