@@ -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,11 +385,11 @@ public function input($fieldName, array $options = array()) {
377385 }
378386 }
379387
380- $ options ['_data ' ] = [
388+ $ options ['templateVars ' ] + = [
381389 'prepend ' => $ prepend ,
382390 'append ' => $ append
383391 ];
384-
392+
385393 return parent ::input ($ fieldName , $ options ) ;
386394 }
387395
@@ -396,16 +404,12 @@ protected function _groupTemplate($options) {
396404 if (!$ this ->templater ()->get ($ groupTemplate )) {
397405 $ groupTemplate = 'formGroup ' ;
398406 }
399- $ data = [
407+ return $ this -> formatTemplate ( $ groupTemplate , [
400408 'input ' => $ options ['input ' ],
401409 '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 );
410+ 'error ' => $ options ['error ' ],
411+ 'templateVars ' => isset ($ options ['options ' ]['templateVars ' ]) ? $ options ['options ' ]['templateVars ' ] : []
412+ ]);
409413 }
410414
411415 /**
@@ -424,7 +428,8 @@ protected function _getDatetimeTemplate ($fields, $options) {
424428 $ inputs = [] ;
425429 foreach ($ fields as $ field => $ in ) {
426430 if ($ this ->_extractOption ($ field , $ options , $ in )) {
427- if ($ field === 'timeFormat ' ) $ field = 'meridian ' ; // Template uses "meridian" instead of timeFormat
431+ if ($ field === 'timeFormat ' )
432+ $ field = 'meridian ' ; // Template uses "meridian" instead of timeFormat
428433 $ inputs [$ field ] = '<div class="col-md-{{colsize}}">{{ ' .$ field .'}}</div> ' ;
429434 }
430435 }
@@ -436,7 +441,8 @@ protected function _getDatetimeTemplate ($fields, $options) {
436441 $ html .= $ inputs [$ v ] ;
437442 }
438443 }
439- return str_replace ('{{colsize}} ' , round (12 / count ($ inputs )), '<div class="row"> ' .$ html .'</div> ' ) ;
444+ return str_replace ('{{colsize}} ' , round (12 / count ($ inputs )),
445+ '<div class="row"> ' .$ html .'</div> ' ) ;
440446 }
441447
442448 /**
0 commit comments