Skip to content

Commit 5114ffe

Browse files
committed
Port fixes from #5616 to 3.0.
FormHelper shared the same issues in 3.0 as it did in 2.x. Given that merging was going to be a nightmare, I've copy&paste merged these changes on to 3.0.
1 parent 0b8b558 commit 5114ffe

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/View/Helper/FormHelper.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,15 +1387,14 @@ public function checkbox($fieldName, array $options = [])
13871387
*/
13881388
public function radio($fieldName, $options = [], array $attributes = [])
13891389
{
1390+
$attributes['options'] = $options;
1391+
$attributes['idPrefix'] = $this->_idPrefix;
13901392
$attributes = $this->_initInputField($fieldName, $attributes);
13911393

13921394
$value = $attributes['val'];
13931395
$hiddenField = isset($attributes['hiddenField']) ? $attributes['hiddenField'] : true;
13941396
unset($attributes['hiddenField']);
13951397

1396-
$attributes['options'] = $options;
1397-
$attributes['idPrefix'] = $this->_idPrefix;
1398-
13991398
$radio = $this->widget('radio', $attributes);
14001399

14011400
$hidden = '';
@@ -2318,7 +2317,18 @@ protected function _initInputField($field, $options = [])
23182317
if ($context->hasError($field)) {
23192318
$options = $this->addClass($options, $this->_config['errorClass']);
23202319
}
2321-
if (!empty($options['disabled'])) {
2320+
$isDisabled = false;
2321+
if (isset($options['disabled'])) {
2322+
$isDisabled = (
2323+
$options['disabled'] === true ||
2324+
$options['disabled'] === 'disabled' ||
2325+
(is_array($options['disabled']) &&
2326+
!empty($options['options']) &&
2327+
array_diff($options['options'], $options['disabled']) === array()
2328+
)
2329+
);
2330+
}
2331+
if ($isDisabled) {
23222332
$options['secure'] = self::SECURE_SKIP;
23232333
}
23242334
if ($options['secure'] === self::SECURE_SKIP) {

tests/TestCase/View/Helper/FormHelperTest.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,10 +1544,13 @@ public function testFormSecuredInput()
15441544

15451545
$result = $this->Form->fields;
15461546
$expected = [
1547-
'ratio', 'population', 'published', 'other',
1548-
'stuff' => '',
1549-
'hidden' => '0',
1550-
'something'
1547+
'ratio',
1548+
'population',
1549+
'published',
1550+
'other',
1551+
'stuff' => '',
1552+
'hidden' => '0',
1553+
'something'
15511554
];
15521555
$this->assertEquals($expected, $result);
15531556

@@ -1645,6 +1648,18 @@ public function testFormSecuredRadio()
16451648
$this->Form->radio('Test.test', $options);
16461649
$expected = ['Test.test'];
16471650
$this->assertEquals($expected, $this->Form->fields);
1651+
1652+
$this->Form->radio('Test.all', $options, [
1653+
'disabled' => ['option1', 'option2']
1654+
]);
1655+
$expected = ['Test.test', 'Test.all' => ''];
1656+
$this->assertEquals($expected, $this->Form->fields);
1657+
1658+
$this->Form->radio('Test.some', $options, [
1659+
'disabled' => ['option1']
1660+
]);
1661+
$expected = ['Test.test', 'Test.all' => '', 'Test.some'];
1662+
$this->assertEquals($expected, $this->Form->fields);
16481663
}
16491664

16501665
/**

0 commit comments

Comments
 (0)