8000 [Form] tweaked previous commit · renegare/symfony@462a8c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 462a8c7

Browse files
committed
[Form] tweaked previous commit
1 parent 91aedf5 commit 462a8c7

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/ScalarToBooleanChoicesTransformer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
1515
use Symfony\Component\Form\DataTransformerInterface;
1616
use Symfony\Component\Form\Exception\UnexpectedTypeException;
17+
use Symfony\Component\Form\Util\FormUtil;
1718

1819
class ScalarToBooleanChoicesTransformer implements DataTransformerInterface
1920
{
@@ -51,18 +52,15 @@ public function transform($value)
5152
throw new UnexpectedTypeException($value, 'scalar');
5253
}
5354

54-
if (is_bool($value) || null === $value) {
55-
$value = (int)$value;
56-
}
57-
5855
try {
5956
$choices = $this->choiceList->getChoices();
6057
} catch (\Exception $e) {
6158
throw new TransformationFailedException('Can not get the choice list', $e->getCode(), $e);
6259
}
6360

61+
$value = FormUtil::toArrayKey($value);
6462
foreach (array_keys($choices) as $key) {
65-
$choices[$key] = (string)$key === (string)$value;
63+
$choices[$key] = $key === $value;
6664
}
6765

6866
return $choices;

0 commit comments

Comments
 (0)
0