From: Matthias Schmidt Date: Sat, 1 Feb 2020 09:03:54 +0000 (+0100) Subject: Fix UserFormField value for empty fields X-Git-Tag: 5.2.2~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0f0fb9b3ee2fb36068f6a06df38e63e18c9e6ec2;p=GitHub%2FWoltLab%2FWCF.git Fix UserFormField value for empty fields --- 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)) {