From 0f0fb9b3ee2fb36068f6a06df38e63e18c9e6ec2 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 1 Feb 2020 10:03:54 +0100 Subject: [PATCH] Fix UserFormField value for empty fields --- .../builder/field/user/UserFormField.class.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php b/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php index 803eb7a5ad..e1b34c1919 100644 --- a/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php @@ -64,19 +64,16 @@ class UserFormField extends AbstractFormField implements IAutoFocusFormField, II */ public function getSaveValue() { if (empty($this->getUsers())) { + if ($this->isNullable()) { + return null; + } + return 0; } return current($this->getUsers())->userID; } - /** - * @inheritDoc - */ - public function hasSaveValue() { - return !$this->allowsMultiple() && !empty($this->getUsers()); - } - /** * @inheritDoc */ @@ -85,7 +82,7 @@ class UserFormField extends AbstractFormField implements IAutoFocusFormField, II if ($this->allowsMultiple()) { $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor('multipleUsers', function(IFormDocument $document, array $parameters) { - if ($this->checkDependencies() && !empty($this->getUsers())) { + if ($this->checkDependencies()) { $parameters[$this->getObjectProperty()] = array_values(array_map(function(UserProfile $user) { return $user->userID; }, $this->getUsers())); @@ -103,6 +100,8 @@ class UserFormField extends AbstractFormField implements IAutoFocusFormField, II */ public function readValue() { if ($this->getDocument()->hasRequestData($this->getPrefixedId())) { + $this->users = []; + $value = $this->getDocument()->getRequestData($this->getPrefixedId()); if (is_string($value)) { -- 2.20.1