@@ -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,23 @@ 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 ' ],
107
+ // when compound the array entries are ignored, we need to cascade the configuration here
108
+ 'empty_data ' => isset ($ options ['empty_data ' ][$ part ]) ? $ options ['empty_data ' ][$ part ] : null ,
105
109
);
106
110
if ('choice ' === $ options ['widget ' ]) {
107
- $ childOptions [$ part ][ 'choice_translation_domain ' ] = false ;
108
- $ childOptions [$ part ][ 'choices ' ] = $ options [$ part ];
109
- $ childOptions [$ part ][ 'placeholder ' ] = $ options ['placeholder ' ][$ part ];
111
+ $ childOptions ['choice_translation_domain ' ] = false ;
112
+ $ childOptions ['choices ' ] = $ options [$ part ];
113
+ $ childOptions ['placeholder ' ] = $ options ['placeholder ' ][$ part ];
110
114
}
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 ]);
115
+ $ childForm = $ builder ->create ($ part , self ::$ widgets [$ options ['widget ' ]], $ childOptions );
124
116
if ('integer ' === $ options ['widget ' ]) {
125
117
$ childForm ->addModelTransformer (
126
118
new ReversedTransformer (
@@ -132,7 +124,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
132
124
}
133
125
}
134
126
if ($ options ['with_invert ' ]) {
135
- $ builder ->add ('invert ' , ' Symfony\Component\Form\Extension\Core\Type\ CheckboxType' , array (
127
+ $ builder ->add ('invert ' , CheckboxType::class , array (
136
128
'label ' => $ options ['labels ' ]['invert ' ],
137
129
'error_bubbling ' => true ,
138
130
'required ' => false ,
@@ -180,6 +172,9 @@ public function configureOptions(OptionsResolver $resolver)
180
172
$ compound = function (Options $ options ) {
181
173
return 'single_text ' !== $ options ['widget ' ];
182
174
};
175
+ $ emptyData = function (Options $ options ) {
176
+ return 'single_text ' === $ options ['widget ' ] ? '' : array ();
177
+ };
183
178
184
179
$ placeholderDefault = function (Options $ options ) {
185
180
return $ options ['required ' ] ? null : '' ;
@@ -238,6 +233,7 @@ public function configureOptions(OptionsResolver $resolver)
238
233
// this option.
239
234
'data_class ' => null ,
240
235
'compound ' => $ compound ,
236
+ 'empty_data ' => $ emptyData ,
241
237
'labels ' => array (),
242
238
)
243
239
);
0 commit comments