@@ -57,39 +57,43 @@ protected function configureListFields(ListMapper $listMapper)
57
57
58
58
protected function configureFormFields (FormMapper $ formMapper )
59
59
{
60
+ $ isSf28 = method_exists ('Symfony\Component\Form\AbstractType ' , 'getBlockPrefix ' );
61
+ $ textType = $ isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\TextType ' : 'text ' ;
62
+ $ doctrineTreeType = $ isSf28 ? 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType ' : 'doctrine_phpcr_odm_tree ' ;
63
+ $ sonataImmutableType = $ isSf28 ? 'Sonata\CoreBundle\Form\Type\ImmutableArrayType ' : 'sonata_type_immutable_array ' ;
64
+
60
65
$ formMapper
61
66
->with ('form.group_general ' , array (
62
67
'translation_domain ' => 'CmfRoutingBundle ' ,
63
68
))
64
69
->add (
65
70
'parent ' ,
66
- ' doctrine_phpcr_odm_tree ' ,
71
+ $ doctrineTreeType ,
67
72
array ('choice_list ' => array (), 'select_root_node ' => true , 'root_node ' => $ this ->routeRoot )
68
73
)
69
- ->add ('name ' , ' text ' )
74
+ ->add ('name ' , $ textType )
70
75
->end ();
71
76
72
77
if (null === $ this ->getParentFieldDescription ()) {
73
78
$ formMapper
74
79
->with ('form.group_general ' , array (
75
80
'translation_domain ' => 'CmfRoutingBundle ' ,
76
81
))
77
- ->add ('content ' , ' doctrine_phpcr_odm_tree ' , array ('choice_list ' => array (), 'required ' => false , 'root_node ' => $ this ->contentRoot ))
82
+ ->add ('content ' , $ doctrineTreeType , array ('choice_list ' => array (), 'required ' => false , 'root_node ' => $ this ->contentRoot ))
78
83
->end ()
79
84
->with ('form.group_advanced ' , array (
80
85
'translation_domain ' => 'CmfRoutingBundle ' ,
81
86
))
82
- ->add ('variablePattern ' , ' text ' , array ('required ' => false ), array ('help ' => 'form.help_variable_pattern ' ))
87
+ ->add ('variablePattern ' , $ textType , array ('required ' => false ), array ('help ' => 'form.help_variable_pattern ' ))
83
88
->add (
84
89
'defaults ' ,
85
- ' sonata_type_immutable_array ' ,
90
+ $ sonataImmutableType ,
86
91
array ('keys ' => $ this ->configureFieldsForDefaults ($ this ->getSubject ()->getDefaults ()))
87
92
)
88
93
->add (
89
94
'options ' ,
90
- 'sonata_type_immutable_array ' ,
91
- array (
92
- 'keys ' => $ this ->configureFieldsForOptions ($ this ->getSubject ()->getOptions ())),
95
+ $ sonataImmutableType ,
96
+ array ('keys ' => $ this ->configureFieldsForOptions ($ this ->getSubject ()->getOptions ())),
93
97
array ('help ' => 'form.help_options ' )
94
98
)
95
99
->end ()
@@ -139,18 +143,21 @@ public function getExportFormats()
139
143
*/
140
144
protected function configureFieldsForDefaults ($ dynamicDefaults )
141
145
{
146
+ $ isSf28 = method_exists ('Symfony\Component\Form\AbstractType ' , 'getBlockPrefix ' );
147
+ $ textType = $ isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\TextType ' : 'text ' ;
148
+
142
149
$ defaults = array (
143
- '_controller ' => array ('_controller ' , ' text ' , array ('required ' => false )),
144
- '_template ' => array ('_template ' , ' text ' , array ('required ' => false )),
145
- 'type ' => array ('type ' , 'cmf_routing_route_type ' , array (
150
+ '_controller ' => array ('_controller ' , $ textType , array ('required ' => false )),
151
+ '_template ' => array ('_template ' , $ textType , array ('required ' => false )),
152
+ 'type ' => array ('type ' , $ isSf28 ? ' Symfony\Cmf\Bundle\RoutingBundle\Form\Type\RouteTypeType ' : 'cmf_routing_route_type ' , array (
146
153
'empty_value ' => '' ,
147
154
'required ' => false ,
148
155
)),
149
156
);
150
157
151
158
foreach ($ dynamicDefaults as $ name => $ value ) {
152
159
if (!isset ($ defaults [$ name ])) {
153
- $ defaults [$ name ] = array ($ name , ' text ' , array ('required ' => false ));
160
+ $ defaults [$ name ] = array ($ name , $ textType , array ('required ' => false ));
154
161
}
155
162
}
156
163
@@ -162,16 +169,16 @@ protected function configureFieldsForDefaults($dynamicDefaults)
162
169
foreach ($ matches as $ match ) {
163
170
$ name = substr ($ match [0 ][0 ], 1 , -1 );
164
171
if (!isset ($ defaults [$ name ])) {
165
- $ defaults [$ name ] = array ($ name , ' text ' , array ('required ' => true ));
172
+ $ defaults [$ name ] = array ($ name , $ textType , array ('required ' => true ));
166
173
}
167
174
}
168
175
}
169
176
170
177
if ($ route && $ route ->getOption ('add_format_pattern ' )) {
171
- $ defaults ['_format ' ] = array ('_format ' , ' text ' , array ('required ' => true ));
178
+ $ defaults ['_format ' ] = array ('_format ' , $ textType , array ('required ' => true ));
172
179
}
173
180
if ($ route && $ route ->getOption ('add_locale_pattern ' )) {
174
- $ defaults ['_locale ' ] = array ('_format ' , ' text ' , array ('required ' => false ));
181
+ $ defaults ['_locale ' ] = array ('_format ' , $ textType , array ('required ' => false ));
175
182
}
176
183
177
184
return $ defaults ;
@@ -186,10 +193,13 @@ protected function configureFieldsForDefaults($dynamicDefaults)
186
193
*/
187
194
protected function configureFieldsForOptions (array $ dynamicOptions )
188
195
{
196
+ $ isSf28 = method_exists ('Symfony\Component\Form\AbstractType ' , 'getBlockPrefix ' );
197
+ $ checkboxType = $ isSf28 ? 'Symfony\Component\Form\Extension\Core\Type\CheckboxType ' : 'checkbox ' ;
198
+
189
199
$ options = array (
190
- 'add_locale_pattern ' => array ('add_locale_pattern ' , ' checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_locale_pattern ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
191
- 'add_format_pattern ' => array ('add_format_pattern ' , ' checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_format_pattern ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
192
- 'add_trailing_slash ' => array ('add_trailing_slash ' , ' checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_trailing_slash ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
200
+ 'add_locale_pattern ' => array ('add_locale_pattern ' , $ checkboxType , array ('required ' => false , 'label ' => 'form.label_add_locale_pattern ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
201
+ 'add_format_pattern ' => array ('add_format_pattern ' , $ checkboxType , array ('required ' => false , 'label ' => 'form.label_add_format_pattern ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
202
+ 'add_trailing_slash ' => array ('add_trailing_slash ' , $ checkboxType , array ('required ' => false , 'label ' => 'form.label_add_trailing_slash ' , 'translation_domain ' => 'CmfRoutingBundle ' )),
193
203
);
194
204
195
205
foreach ($ dynamicOptions as $ name => $ value ) {
0 commit comments