@@ -59,24 +59,40 @@ protected function configureListFields(ListMapper $listMapper)
5959 protected function configureFormFields (FormMapper $ formMapper )
6060 {
6161 $ formMapper
62- ->with ('form.group_general ' )
63- ->add (
64- 'parent ' ,
65- 'doctrine_phpcr_odm_tree ' ,
66- array ('choice_list ' => array (), 'select_root_node ' => true , 'root_node ' => $ this ->routeRoot )
67- )
68- ->add ('name ' , 'text ' )
62+ ->with ('form.group_general ' , array (
63+ 'translation_domain ' => 'CmfRoutingBundle ' ,
64+ ))
65+ ->add (
66+ 'parent ' ,
67+ 'doctrine_phpcr_odm_tree ' ,
68+ array ('choice_list ' => array (), 'select_root_node ' => true , 'root_node ' => $ this ->routeRoot )
69+ )
70+ ->add ('name ' , 'text ' )
6971 ->end ();
7072
7173 if (null === $ this ->getParentFieldDescription ()) {
7274 $ formMapper
73- ->with ('form.group_general ' )
75+ ->with ('form.group_general ' , array (
76+ 'translation_domain ' => 'CmfRoutingBundle ' ,
77+ ))
7478 ->add ('content ' , 'doctrine_phpcr_odm_tree ' , array ('choice_list ' => array (), 'required ' => false , 'root_node ' => $ this ->contentRoot ))
7579 ->end ()
76- ->with ('form.group_advanced ' )
80+ ->with ('form.group_advanced ' , array (
81+ 'translation_domain ' => 'CmfRoutingBundle ' ,
82+ ))
7783 ->add ('variablePattern ' , 'text ' , array ('required ' => false ), array ('help ' => 'form.help_variable_pattern ' ))
78- ->add ('defaults ' , 'sonata_type_immutable_array ' , array ('keys ' => $ this ->configureFieldsForDefaults ()))
79- ->add ('options ' , 'sonata_type_immutable_array ' , array ('keys ' => $ this ->configureFieldsForOptions ()), array ('help ' => 'form.help_options ' ))
84+ ->add (
85+ 'defaults ' ,
86+ 'sonata_type_immutable_array ' ,
87+ array ('keys ' => $ this ->configureFieldsForDefaults ($ this ->getSubject ()->getDefaults ()))
88+ )
89+ ->add (
90+ 'options ' ,
91+ 'sonata_type_immutable_array ' ,
92+ array (
93+ 'keys ' => $ this ->configureFieldsForOptions ($ this ->getSubject ()->getOptions ())),
94+ array ('help ' => 'form.help_options ' )
95+ )
8096 ->end ()
8197 ->end ();
8298 }
@@ -110,7 +126,14 @@ public function getExportFormats()
110126 return array ();
111127 }
112128
113- protected function configureFieldsForDefaults ()
129+ /**
130+ * Provide default route defaults and extract defaults from $dynamicDefaults.
131+ *
132+ * @param array $dynamicDefaults
133+ *
134+ * @return array Value for sonata_type_immutable_array
135+ */
136+ protected function configureFieldsForDefaults ($ dynamicDefaults )
114137 {
115138 $ defaults = array (
116139 '_controller ' => array ('_controller ' , 'text ' , array ('required ' => false )),
@@ -121,14 +144,13 @@ protected function configureFieldsForDefaults()
121144 )),
122145 );
123146
124- $ dynamicDefaults = $ this ->getSubject ()->getDefaults ();
125147 foreach ($ dynamicDefaults as $ name => $ value ) {
126148 if (!isset ($ defaults [$ name ])) {
127149 $ defaults [$ name ] = array ($ name , 'text ' , array ('required ' => false ));
128150 }
129151 }
130152
131- //parse variable pattern and add defaults for it - taken from routecompiler
153+ //parse variable pattern and add defaults for tokens - taken from routecompiler
132154 /** @var $route Route */
133155 $ route = $ this ->subject ;
134156 if ($ route && $ route ->getVariablePattern ()) {
@@ -141,18 +163,31 @@ protected function configureFieldsForDefaults()
141163 }
142164 }
143165
166+ if ($ route && $ route ->getOption ('add_format_pattern ' )) {
167+ $ defaults ['_format ' ] = array ('_format ' , 'text ' , array ('required ' => true ));
168+ }
169+ if ($ route && $ route ->getOption ('add_locale_pattern ' )) {
170+ $ defaults ['_locale ' ] = array ('_format ' , 'text ' , array ('required ' => false ));
171+ }
172+
144173 return $ defaults ;
145174 }
146175
147- protected function configureFieldsForOptions ()
176+ /**
177+ * Provide default options and extract options from $dynamicOptions.
178+ *
179+ * @param array $dynamicOptions
180+ *
181+ * @return array Value for sonata_type_immutable_array
182+ */
183+ protected function configureFieldsForOptions (array $ dynamicOptions )
148184 {
149185 $ options = array (
150- array ('add_locale_pattern ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_locale_pattern ' , 'translation_domain ' => $ this -> translationDomain )),
151- array ('add_format_pattern ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_format_pattern ' , 'translation_domain ' => $ this -> translationDomain )),
152- array ('add_trailing_slash ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_trailing_slash ' , 'translation_domain ' => $ this -> translationDomain )),
186+ ' add_locale_pattern ' => array ('add_locale_pattern ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_locale_pattern ' , 'translation_domain ' => ' CmfRoutingBundle ' )),
187+ ' add_format_pattern ' => array ('add_format_pattern ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_format_pattern ' , 'translation_domain ' => ' CmfRoutingBundle ' )),
188+ ' add_trailing_slash ' => array ('add_trailing_slash ' , 'checkbox ' , array ('required ' => false , 'label ' => 'form.label_add_trailing_slash ' , 'translation_domain ' => ' CmfRoutingBundle ' )),
153189 );
154190
155- $ dynamicOptions = $ this ->getSubject ()->getOptions ();
156191 foreach ($ dynamicOptions as $ name => $ value ) {
157192 if (!isset ($ options [$ name ])) {
158193 $ options [$ name ] = array ($ name , 'text ' , array ('required ' => false ));
0 commit comments