@@ -27,16 +27,7 @@ class CollectionType extends AbstractType
27
27
public function buildForm (FormBuilderInterface $ builder , array $ options )
28
28
{
29
29
if ($ options ['allow_add ' ] && $ options ['prototype ' ]) {
30
- $ prototypeOptions = array_replace (array (
31
- 'required ' => $ options ['required ' ],
32
- 'label ' => $ options ['prototype_name ' ].'label__ ' ,
33
- ), $ options ['entry_options ']);
34
-
35
- if (null !== $ options ['prototype_data ' ]) {
36
- $ prototypeOptions ['data ' ] = $ options ['prototype_data ' ];
37
- }
38
-
39
- $ prototype = $ builder ->create ($ options ['prototype_name ' ], $ options ['entry_type ' ], $ prototypeOptions );
30
+ $ prototype = $ builder ->create ($ options ['prototype_name ' ], $ options ['entry_type ' ], $ options ['prototype_options ' ]);
40
31
$ builder ->setAttribute ('prototype ' , $ prototype ->getForm ());
41
32
}
42
33
@@ -81,24 +72,53 @@ public function finishView(FormView $view, FormInterface $form, array $options)
81
72
*/
82
73
public function configureOptions (OptionsResolver $ resolver )
83
74
{
84
- $ entryOptionsNormalizer = function (Options $ options , $ value ) {
85
- $ value ['block_name ' ] = 'entry ' ;
75
+ $ entryOptionsNormalizer = function (Options $ options , $ entryOptions ) {
76
+ $ entryOptions ['block_name ' ] = 'entry ' ;
86
77
87
- return $ value ;
78
+ return $ entryOptions ;
79
+ };
80
+
81
+ $ prototypeOptionsNormalizer = function (Options $ options , $ prototypeOptions ) {
82
+ // Default to 'entry_options' option
83
+ $ prototypeOptions = array_replace ($ options ['entry_options ' ], $ prototypeOptions );
84
+
85
+ if (null !== $ options ['prototype_data ' ]) {
86
+ @trigger_error ('The "prototype_data" option is deprecated since version 3.1 and will be removed in 4.0. You should use "prototype_options" option instead. ' , E_USER_DEPRECATED );
87
+
88
+ // BC, Let 'prototype_data' option override `$entryOptions['data']`
89
+ $ prototypeOptions ['data ' ] = $ options ['prototype_data ' ];
90
+ }
91
+
92
+ return array_replace (array (
93
+ // Use the collection required state
94
+ 'required ' => $ options ['required ' ],
95
+ 'label ' => $ options ['prototype_name ' ].'label__ ' ,
96
+ ), $ prototypeOptions );
88
97
};
89
98
90
99
$ resolver ->setDefaults (array (
91
- 'allow_add ' => false ,
92
- 'allow_delete ' => false ,
93
- 'prototype ' => true ,
94
- 'prototype_data ' => null ,
95
- 'prototype_name ' => '__name__ ' ,
96
100
'entry_type ' => __NAMESPACE__ .'\TextType ' ,
97
101
'entry_options ' => array (),
102
+ 'prototype ' => true ,
103
+ 'prototype_data ' => null , // deprecated
104
+ 'prototype_name ' => '__name__ ' ,
105
+ 'prototype_options ' => array (),
106
+ 'allow_add ' => false ,
107
+ 'allow_delete ' => false ,
98
108
'delete_empty ' => false ,
99
109
));
100
110
101
111
$ resolver ->setNormalizer ('entry_options ' , $ entryOptionsNormalizer );
112
+ $ resolver ->setNormalizer ('prototype_options ' , $ prototypeOptionsNormalizer );
113
+
114
+ $ resolver ->setAllowedTypes ('entry_type ' , array ('string ' , 'Symfony\Component\Form\FormTypeInterface ' ));
115
+ $ resolver ->setAllowedTypes ('entry_options ' , 'array ' );
116
+ $ resolver ->setAllowedTypes ('prototype ' , 'bool ' );
117
+ $ resolver ->setAllowedTypes ('prototype_name ' , 'string ' );
118
+ $ resolver ->setAllowedTypes ('prototype_options ' , 'array ' );
119
+ $ resolver ->setAllowedTypes ('allow_add ' , 'bool ' );
120
+ $ resolver ->setAllowedTypes ('allow_delete ' , 'bool ' );
121
+ $ resolver ->setAllowedTypes ('delete_empty ' , 'bool ' );
102
122
}
103
123
104
124
/**
0 commit comments