From c5fdfb9249e75f354acbf8652c51c171d2fee0f9 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 6 May 2018 09:25:21 +0200 Subject: [PATCH] Allow more values to be passed to `BooleanFormField::value()` See #2509 --- .../system/form/builder/field/BooleanFormField.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php index 3addaf84ad..5a6f769e0e 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/BooleanFormField.class.php @@ -59,7 +59,13 @@ class BooleanFormField extends AbstractFormField { * @return static this field */ public function value($value): IFormField { - if (!is_bool($value)) { + if (is_string($value) && in_array($value, ['0', '1', 'true', 'false'])) { + $value = ($value === '1' || $value === 'true'); + } + if (is_int($value) && ($value === 0 || $value === 1)) { + $value = ($value === 1); + } + else if (!is_bool($value)) { throw new \InvalidArgumentException("Given value is no bool, " . gettype($value) . " given."); } -- 2.20.1