Skip to content

Commit fd48632

Browse files
author
Dominic Tubach
committed
Fix radios input with booleans
1 parent 521da17 commit fd48632

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/Form/Control/Callbacks/OptionValueCallbacks.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ public static function validate(array $element, FormStateInterface $formState):
5252
* @return mixed
5353
*/
5454
public static function value(array $element, $input, FormStateInterface $formState) {
55+
$defaultUsed = FALSE;
5556
if (FALSE === $input) {
5657
$input = $element['#default_value'] ?? NULL;
58+
$defaultUsed = TRUE;
5759
}
5860

5961
if (NULL === $input) {
@@ -64,28 +66,11 @@ public static function value(array $element, $input, FormStateInterface $formSta
6466
return NULL;
6567
}
6668

67-
if (in_array($input, $element['#_option_values'], TRUE)
68-
|| self::isIntegerish($input) && in_array((int) $input, $element['#_option_values'], TRUE)
69-
) {
69+
if (!$defaultUsed && is_string($input) && array_key_exists($input, $element['#_option_values'])) {
7070
$input = $element['#_option_values'][$input];
7171
}
7272

7373
return $input;
7474
}
7575

76-
/**
77-
* @param mixed $value
78-
*
79-
* @return bool
80-
*
81-
* @phpstan-assert-if-true float|string|int $value
82-
*/
83-
private static function isIntegerish($value): bool {
84-
if (\is_string($value)) {
85-
$value = \trim($value);
86-
}
87-
88-
return \is_numeric($value) && $value == (string) $value;
89-
}
90-
9176
}

0 commit comments

Comments
 (0)