@@ -20,6 +20,13 @@ class FormHelper extends Helper
20
20
*/
21
21
protected $ _align ;
22
22
23
+ /**
24
+ * The method to use when creating a control element for a form
25
+ *
26
+ * @var string
27
+ */
28
+ protected $ _controlMethod = 'input ' ;
29
+
23
30
/**
24
31
* Default Bootstrap string templates.
25
32
*
@@ -102,6 +109,10 @@ public function __construct(View $View, array $config = [])
102
109
103
110
$ this ->_defaultWidgets = $ this ->_widgets + $ this ->_defaultWidgets ;
104
111
112
+ if (method_exists ('Cake\View\Helper\FormHelper ' , 'control ' )) {
113
+ $ this ->_controlMethod = 'control ' ;
114
+ }
115
+
105
116
parent ::__construct ($ View , $ config );
106
117
}
107
118
@@ -169,8 +180,27 @@ public function submit($caption = null, array $options = [])
169
180
* @param string $fieldName This should be "Modelname.fieldname".
170
181
* @param array $options Each type of input takes different options.
171
182
* @return string Completed form widget.
183
+ * @deprecated Use control() instead.
172
184
*/
173
185
public function input ($ fieldName , array $ options = [])
186
+ {
187
+ return $ this ->control ($ fieldName , $ options );
188
+ }
189
+
190
+ /**
191
+ * Generates a form input element complete with label and wrapper div.
192
+ *
193
+ * Adds extra option besides the ones supported by parent class method:
194
+ * - `append` - Append addon to input.
195
+ * - `prepend` - Prepend addon to input.
196
+ * - `inline` - Boolean for generating inline checkbox/radio.
197
+ * - `help` - Help text of include in the input container.
198
+ *
199
+ * @param string $fieldName This should be "Modelname.fieldname".
200
+ * @param array $options Each type of input takes different options.
201
+ * @return string Completed form widget.
202
+ */
203
+ public function control ($ fieldName , array $ options = [])
174
204
{
175
205
$ options += [
176
206
'prepend ' => null ,
@@ -246,7 +276,9 @@ public function input($fieldName, array $options = [])
246
276
);
247
277
}
248
278
249
- $ result = parent ::input ($ fieldName , $ options );
279
+ $ controlMethod = $ this ->_controlMethod ;
280
+ $ result = parent ::$ controlMethod ($ fieldName , $ options );
281
+
250
282
if ($ newTemplates ) {
251
283
$ this ->templater ()->pop ();
252
284
}
0 commit comments