@@ -29,7 +29,7 @@ class BootstrapFormHelper extends FormHelper {
2929 use BootstrapTrait ;
3030
3131 public $ helpers = [
32- 'Html ' ,
32+ 'Html ' ,
3333 'Url ' ,
3434 'bHtml ' => [
3535 'className ' => 'Bootstrap.BootstrapHtml '
@@ -102,7 +102,7 @@ class BootstrapFormHelper extends FormHelper {
102102 'datetime ' => ['Cake\View\Widget\DateTimeWidget ' , 'select ' ],
103103 '_default ' => ['Cake\View\Widget\BasicWidget ' ],
104104 ];
105-
105+
106106 public $ horizontal = false ;
107107 public $ inline = false ;
108108 public $ colSize ;
@@ -151,7 +151,7 @@ public function __construct (\Cake\View\View $view, array $config = []) {
151151 $ this ->_defaultConfig ['templateClass ' ] = 'Bootstrap\View\BootstrapStringTemplate ' ;
152152 parent ::__construct ($ view , $ config );
153153 }
154-
154+
155155 /**
156156 *
157157 * Replace the templates with the ones specified by newTemplates, call the specified function
@@ -326,40 +326,48 @@ public function wrap ($input, $prepend, $append) {
326326 protected function _wrap ($ input , $ prepend , $ append ) {
327327 return '<div class="input-group"> ' .$ prepend .$ input .$ append .'</div> ' ;
328328 }
329-
330- /**
331- *
329+
330+ /**
331+ *
332332 * Create & return an input block (Twitter Boostrap Like).
333- *
333+ *
334334 * New options:
335- * - prepend:
336- * -> string: Add <span class="add-on"> before the input
337- * -> array: Add elements in array before inputs
338- * - append: Same as prepend except it add elements after input
339- *
335+ * - prepend:
336+ * -> string: Add <span class="add-on"> before the input
337+ * -> array: Add elements in array before inputs
338+ * - append: Same as prepend except it add elements after input
339+ *
340340 **/
341341 public function input ($ fieldName , array $ options = array ()) {
342-
342+
343+ $ options += [
344+ 'templateVars ' => [],
345+ 'prepend ' => false ,
346+ 'append ' => false ,
347+ 'help ' => false ,
348+ 'inline ' => false
349+ ];
350+
343351 $ options = $ this ->_parseOptions ($ fieldName , $ options );
344352
345- $ prepend = $ this -> _extractOption ( 'prepend ' , $ options , false ) ;
353+ $ prepend = $ options [ 'prepend ' ] ;
346354 unset($ options ['prepend ' ]);
347- $ append = $ this -> _extractOption ( 'append ' , $ options , false ) ;
355+ $ append = $ options [ 'append ' ] ;
348356 unset($ options ['append ' ]);
349357 if ($ prepend || $ append ) {
350358 $ prepend = $ this ->prepend (null , $ prepend );
351359 $ append = $ this ->append (null , $ append );
352360 }
353361
354- $ help = $ this -> _extractOption ( 'help ' , $ options , '' ) ;
362+ $ help = $ options [ 'help ' ] ;
355363 unset($ options ['help ' ]);
356364 if ($ help ) {
357365 $ append .= '<p class="help-block"> ' .$ help .'</p> ' ;
358366 }
359367
360- $ inline = $ this -> _extractOption ( 'inline ' , $ options , '' ) ;
368+ $ inline = $ options [ 'inline ' ] ;
361369 unset ($ options ['inline ' ]) ;
362-
370+
363371 if ($ options ['type ' ] === 'radio ' ) {
364372 $ options ['templates ' ] = [] ;
365373 if ($ inline ) {
@@ -377,35 +385,12 @@ public function input($fieldName, array $options = array()) {
377385 }
378386 }
379387
380- $ options ['_data ' ] = [
388+ $ options ['templateVars ' ] + = [
381389 'prepend ' => $ prepend ,
382390 'append ' => $ append
383391 ];
384-
385- return parent ::input ($ fieldName , $ options ) ;
386- }
387392
388- /**
389- * Generates an group template element
390- *
391- * @param array $options The options for group template
392- * @return string The generated group template
393- */
394- protected function _groupTemplate ($ options ) {
395- $ groupTemplate = $ options ['options ' ]['type ' ] . 'FormGroup ' ;
396- if (!$ this ->templater ()->get ($ groupTemplate )) {
397- $ groupTemplate = 'formGroup ' ;
398- }
399- $ data = [
400- 'input ' => $ options ['input ' ],
401- 'label ' => $ options ['label ' ],
402- 'error ' => $ options ['error ' ]
403- ];
404- if (isset ($ options ['options ' ]['_data ' ])) {
405- $ data = array_merge ($ data , $ options ['options ' ]['_data ' ]);
406- unset($ options ['options ' ]['_data ' ]);
407- }
408- return $ this ->formatTemplate ($ groupTemplate , $ data );
393+ return parent ::input ($ fieldName , $ options ) ;
409394 }
410395
411396 /**
@@ -424,7 +409,8 @@ protected function _getDatetimeTemplate ($fields, $options) {
424409 $ inputs = [] ;
425410 foreach ($ fields as $ field => $ in ) {
426411 if ($ this ->_extractOption ($ field , $ options , $ in )) {
427- if ($ field === 'timeFormat ' ) $ field = 'meridian ' ; // Template uses "meridian" instead of timeFormat
412+ if ($ field === 'timeFormat ' )
413+ $ field = 'meridian ' ; // Template uses "meridian" instead of timeFormat
428414 $ inputs [$ field ] = '<div class="col-md-{{colsize}}">{{ ' .$ field .'}}</div> ' ;
429415 }
430416 }
@@ -436,7 +422,8 @@ protected function _getDatetimeTemplate ($fields, $options) {
436422 $ html .= $ inputs [$ v ] ;
437423 }
438424 }
439- return str_replace ('{{colsize}} ' , round (12 / count ($ inputs )), '<div class="row"> ' .$ html .'</div> ' ) ;
425+ return str_replace ('{{colsize}} ' , round (12 / count ($ inputs )),
426+ '<div class="row"> ' .$ html .'</div> ' ) ;
440427 }
441428
442429 /**
0 commit comments