@@ -38,9 +38,9 @@ class DateIntervalType extends AbstractType
38
38
'seconds ' ,
39
39
);
40
40
private static $ widgets = array (
41
- 'text ' => ' Symfony\Component\Form\Extension\Core\Type\ TextType' ,
42
- 'integer ' => ' Symfony\Component\Form\Extension\Core\Type\ IntegerType' ,
43
- 'choice ' => ' Symfony\Component\Form\Extension\Core\Type\ ChoiceType' ,
41
+ 'text ' => TextType::class ,
42
+ 'integer ' => IntegerType::class ,
43
+ 'choice ' => ChoiceType::class ,
44
44
);
45
45
46
46
/**
@@ -96,31 +96,21 @@ public function buildForm(FormBuilderInterface $builder, array $options)
96
96
if ('single_text ' === $ options ['widget ' ]) {
97
97
$ builder ->addViewTransformer (new DateIntervalToStringTransformer ($ format ));
98
98
} else {
99
- $ childOptions = array ();
100
99
foreach ($ this ->timeParts as $ part ) {
101
100
if ($ options ['with_ ' .$ part ]) {
102
- $ childOptions[ $ part ] = array (
101
+ $ childOptions = array (
103
102
'error_bubbling ' => true ,
104
103
'label ' => $ options ['labels ' ][$ part ],
104
+ // Append generic carry-along options
105
+ 'required ' => $ options ['required ' ],
106
+ 'translation_domain ' => $ options ['translation_domain ' ],
105
107
);
106
108
if ('choice ' === $ options ['widget ' ]) {
107
- $ childOptions [$ part ][ 'choice_translation_domain ' ] = false ;
108
- $ childOptions [$ part ][ 'choices ' ] = $ options [$ part ];
109
- $ childOptions [$ part ][ 'placeholder ' ] = $ options ['placeholder ' ][$ part ];
109
+ $ childOptions ['choice_translation_domain ' ] = false ;
110
+ $ childOptions ['choices ' ] = $ options [$ part ];
111
+ $ childOptions ['placeholder ' ] = $ options ['placeholder ' ][$ part ];
110
112
}
111
- }
112
- }
113
- // Append generic carry-along options
114
- foreach (array ('required ' , 'translation_domain ' ) as $ passOpt ) {
115
- foreach ($ this ->timeParts as $ part ) {
116
- if ($ options ['with_ ' .$ part ]) {
117
- $ childOptions [$ part ][$ passOpt ] = $ options [$ passOpt ];
118
- }
119
- }
120
- }
121
- foreach ($ this ->timeParts as $ part ) {
122
- if ($ options ['with_ ' .$ part ]) {
123
- $ childForm = $ builder ->create ($ part , self ::$ widgets [$ options ['widget ' ]], $ childOptions [$ part ]);
113
+ $ childForm = $ builder ->create ($ part , self ::$ widgets [$ options ['widget ' ]], $ childOptions );
124
114
if ('integer ' === $ options ['widget ' ]) {
125
115
$ childForm ->addModelTransformer (
126
116
new ReversedTransformer (
@@ -132,7 +122,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
132
122
}
133
123
}
134
124
if ($ options ['with_invert ' ]) {
135
- $ builder ->add ('invert ' , ' Symfony\Component\Form\Extension\Core\Type\ CheckboxType' , array (
125
+ $ builder ->add ('invert ' , CheckboxType::class , array (
136
126
'label ' => $ options ['labels ' ]['invert ' ],
137
127
'error_bubbling ' => true ,
138
128
'required ' => false ,
@@ -180,6 +170,9 @@ public function configureOptions(OptionsResolver $resolver)
180
170
$ compound = function (Options $ options ) {
181
171
return 'single_text ' !== $ options ['widget ' ];
182
172
};
173
+ $ emptyData = function (Options $ options ) {
174
+ return 'single_text ' === $ options ['widget ' ] ? '' : array ();
175
+ };
183
176
184
177
$ placeholderDefault = function (Options $ options ) {
185
178
return $ options ['required ' ] ? null : '' ;
@@ -238,6 +231,7 @@ public function configureOptions(OptionsResolver $resolver)
238
231
// this option.
239
232
'data_class ' => null ,
240
233
'compound ' => $ compound ,
234
+ 'empty_data ' => $ emptyData ,
241
235
'labels ' => array (),
242
236
)
243
237
);
0 commit comments