diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 75250196..c2878c86 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -189,7 +189,14 @@ public function input($fieldName, array $options = []) 'templateVars' => [] ]; $options = $this->_parseOptions($fieldName, $options); - $reset = $this->templates(); + + $newTemplates = $options['templates']; + if ($newTemplates) { + $this->templater()->push(); + $templateMethod = is_string($options['templates']) ? 'load' : 'add'; + $this->templater()->{$templateMethod}($options['templates']); + $options['templates'] = []; + } switch ($options['type']) { case 'checkbox': @@ -203,22 +210,16 @@ public function input($fieldName, array $options = []) break; case 'radio': $isInline = (isset($options['inline']) && $options['inline'] === true); - - $templates = []; if ($isInline && $this->_align !== 'horizontal') { - $templates['formGroup'] = $this->templater()->get('radioInlineFormGroup'); + $options['templates']['formGroup'] = $this->templater()->get('radioInlineFormGroup'); } if (!$isInline) { - $templates['nestingLabel'] = $this->templater()->get('radioNestingLabel'); + $options['templates']['nestingLabel'] = $this->templater()->get('radioNestingLabel'); } - - $this->templater()->add($templates); break; case 'select': if (isset($options['multiple']) && $options['multiple'] === 'checkbox') { - $this->templater()->add([ - 'checkboxWrapper' => $this->templater()->get('multipleCheckboxWrapper') - ]); + $options['templates']['checkboxWrapper'] = $this->templater()->get('multipleCheckboxWrapper'); $options['type'] = 'multicheckbox'; } break; @@ -243,7 +244,9 @@ public function input($fieldName, array $options = []) } $result = parent::input($fieldName, $options); - $this->templates($reset); + if ($newTemplates) { + $this->templater()->pop(); + } return $result; } diff --git a/tests/TestCase/View/Helper/FormHelperTest.php b/tests/TestCase/View/Helper/FormHelperTest.php index 22f71a8a..93ce3439 100644 --- a/tests/TestCase/View/Helper/FormHelperTest.php +++ b/tests/TestCase/View/Helper/FormHelperTest.php @@ -656,6 +656,62 @@ public function testInlineRadioInputHorizontal() $this->assertHtml($expected, $result); } + /** + * https://github.com/FriendsOfCake/bootstrap-ui/pull/113 + * + * @return void + */ + public function testRadioInputCustomTemplate() + { + $templates = [ + 'radioNestingLabel' => '