@@ -38,9 +38,9 @@ class DateIntervalType extends AbstractType
3838 'seconds ' ,
3939 );
4040 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 ,
4444 );
4545
4646 /**
@@ -96,31 +96,23 @@ public function buildForm(FormBuilderInterface $builder, array $options)
9696 if ('single_text ' === $ options ['widget ' ]) {
9797 $ builder ->addViewTransformer (new DateIntervalToStringTransformer ($ format ));
9898 } else {
99- $ childOptions = array ();
10099 foreach ($ this ->timeParts as $ part ) {
101100 if ($ options ['with_ ' .$ part ]) {
102- $ childOptions[ $ part ] = array (
101+ $ childOptions = array (
103102 'error_bubbling ' => true ,
104103 '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 ,
105109 );
106110 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 ];
110114 }
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 );
124116 if ('integer ' === $ options ['widget ' ]) {
125117 $ childForm ->addModelTransformer (
126118 new ReversedTransformer (
@@ -132,7 +124,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
132124 }
133125 }
134126 if ($ options ['with_invert ' ]) {
135- $ builder ->add ('invert ' , ' Symfony\Component\Form\Extension\Core\Type\ CheckboxType' , array (
127+ $ builder ->add ('invert ' , CheckboxType::class , array (
136128 'label ' => $ options ['labels ' ]['invert ' ],
137129 'error_bubbling ' => true ,
138130 'required ' => false ,
@@ -180,6 +172,9 @@ public function configureOptions(OptionsResolver $resolver)
180172 $ compound = function (Options $ options ) {
181173 return 'single_text ' !== $ options ['widget ' ];
182174 };
175+ $ emptyData = function (Options $ options ) {
176+ return 'single_text ' === $ options ['widget ' ] ? '' : array ();
177+ };
183178
184179 $ placeholderDefault = function (Options $ options ) {
185180 return $ options ['required ' ] ? null : '' ;
@@ -238,6 +233,7 @@ public function configureOptions(OptionsResolver $resolver)
238233 // this option.
239234 'data_class ' => null ,
240235 'compound ' => $ compound ,
236+ 'empty_data ' => $ emptyData ,
241237 'labels ' => array (),
242238 )
243239 );
0 commit comments