Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ class FormHelper extends CoreFormHelper
'checkboxFormGroup' =>
'{{input}}{{label}}',
'checkboxWrapper' =>
'<div class="form-check{{variant}}">{{label}}</div>',
'<div class="form-check{{variant}}">{{input}}{{label}}</div>',
'checkboxInlineWrapper' =>
'<div class="form-check{{variant}} form-check-inline">{{label}}</div>',
'<div class="form-check{{variant}} form-check-inline">{{input}}{{label}}</div>',
'radioContainer' =>
'<div{{containerAttrs}} class="{{containerClass}}{{type}}{{required}}" role="group" ' .
'aria-labelledby="{{groupId}}">{{content}}{{help}}</div>',
Expand All @@ -187,9 +187,9 @@ class FormHelper extends CoreFormHelper
'radioLabel' =>
'<label{{attrs}}>{{text}}{{tooltip}}</label>',
'radioWrapper' =>
'<div class="form-check">{{hidden}}{{label}}</div>',
'<div class="form-check">{{hidden}}{{input}}{{label}}</div>',
'radioInlineWrapper' =>
'<div class="form-check form-check-inline">{{label}}</div>',
'<div class="form-check form-check-inline">{{input}}{{label}}</div>',
'staticControl' =>
'<p class="form-control-plaintext">{{content}}</p>',
'inputGroupContainer' =>
Expand Down Expand Up @@ -453,7 +453,6 @@ public function control(string $fieldName, array $options = []): string
'prepend' => null,
'append' => null,
'inline' => null,
'nestedInput' => false,
'switch' => null,
'type' => null,
'label' => null,
Expand All @@ -469,6 +468,7 @@ public function control(string $fieldName, array $options = []): string
'spacing' => null,
];
$options = $this->parseOptions($fieldName, $options);
$options['nestedInput'] ??= $this->getConfig('nestedCheckboxAndRadio');

$newTemplates = $options['templates'];
if ($newTemplates) {
Expand Down Expand Up @@ -508,6 +508,7 @@ public function control(string $fieldName, array $options = []): string
$options['injectErrorClass'] = $this->getConfig('templates.errorClass');
}

$nestedInput = $options['nestedInput'];
unset(
$options['formGroupPosition'],
$options['feedbackStyle'],
Expand All @@ -517,7 +518,16 @@ public function control(string $fieldName, array $options = []): string
$options['switch'],
);

$result = parent::control($fieldName, $options);
// Core `control()` only honors the `nestedInput` option for checkboxes.
// Radio and multi-checkbox inputs read it from the `nestedCheckboxAndRadio`
// config, so set it for the duration of the call.
$nestedCheckboxAndRadio = $this->getConfig('nestedCheckboxAndRadio');
$this->setConfig('nestedCheckboxAndRadio', $nestedInput);
try {
$result = parent::control($fieldName, $options);
} finally {
$this->setConfig('nestedCheckboxAndRadio', $nestedCheckboxAndRadio);
}

$result = $this->postProcessElement($result, $fieldName, $options);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2262,9 +2262,8 @@ public function testDefaultAlignMultipleCheckboxControlOptionsGroupsAndSingleEnt
'class' => 'custominputclass',
],
30 => [
'text' => 'option 5 without label',
'text' => 'option 5',
'value' => 30,
'label' => false,
],
40 => [
'text' => 'option 6',
Expand Down Expand Up @@ -2359,6 +2358,9 @@ public function testDefaultAlignMultipleCheckboxControlOptionsGroupsAndSingleEnt
'id' => 'users-30',
'value' => 30,
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-30']],
'option 5',
'/label',
'/div',
['div' => ['class' => 'form-check']],
['input' => [
Expand Down Expand Up @@ -2488,9 +2490,8 @@ public function testDefaultAlignMultipleCheckboxControlOptionsGroupsAndSingleEnt
'class' => 'custominputclass',
],
30 => [
'text' => 'option 5 without label',
'text' => 'option 5',
'value' => 30,
'label' => false,
],
40 => [
'text' => 'option 6',
Expand Down Expand Up @@ -2579,13 +2580,16 @@ public function testDefaultAlignMultipleCheckboxControlOptionsGroupsAndSingleEnt
'/label',
'/div',
['div' => ['class' => 'form-check']],
['input' => [
'class' => 'form-check-input',
'type' => 'checkbox',
'name' => 'users[]',
'id' => 'users-30',
'value' => 30,
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-30']],
['input' => [
'class' => 'form-check-input',
'type' => 'checkbox',
'name' => 'users[]',
'id' => 'users-30',
'value' => 30,
]],
'option 5',
'/label',
'/div',
['div' => ['class' => 'form-check']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-40']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2517,9 +2517,8 @@ public function testHorizontalAlignMultipleCheckboxControlOptionsGroupsAndSingle
'class' => 'custominputclass',
],
30 => [
'text' => 'option 5 without label',
'text' => 'option 5',
'value' => 30,
'label' => false,
],
40 => [
'text' => 'option 6',
Expand Down Expand Up @@ -2615,6 +2614,9 @@ public function testHorizontalAlignMultipleCheckboxControlOptionsGroupsAndSingle
'id' => 'users-30',
'value' => 30,
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-30']],
'option 5',
'/label',
'/div',
['div' => ['class' => 'form-check']],
['input' => [
Expand Down Expand Up @@ -2761,9 +2763,8 @@ public function testHorizontalAlignMultipleCheckboxControlOptionsGroupsAndSingle
'class' => 'custominputclass',
],
30 => [
'text' => 'option 5 without label',
'text' => 'option 5',
'value' => 30,
'label' => false,
],
40 => [
'text' => 'option 6',
Expand Down Expand Up @@ -2853,13 +2854,16 @@ public function testHorizontalAlignMultipleCheckboxControlOptionsGroupsAndSingle
'/label',
'/div',
['div' => ['class' => 'form-check']],
['input' => [
'class' => 'form-check-input',
'type' => 'checkbox',
'name' => 'users[]',
'id' => 'users-30',
'value' => 30,
]],
['label' => ['class' => 'form-check-label', 'for' => 'users-30']],
['input' => [
'class' => 'form-check-input',
'type' => 'checkbox',
'name' => 'users[]',
'id' => 'users-30',
'value' => 30,
]],
'option 5',
'/label',
'/div',
['div' => ['class' => 'form-check']],
['label' => ['class' => 'customlabelclass', 'for' => 'users-40']],
Expand Down
Loading