Fix UserFormField value for empty fields
authorMatthias Schmidt <gravatronics@live.com>
Sat, 1 Feb 2020 09:03:54 +0000 (10:03 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 1 Feb 2020 09:03:54 +0000 (10:03 +0100)
wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php

index 803eb7a5ad830de7deb64745a05d2d1d1ea39a03..e1b34c1919f76cd70f50fcabc5aee2efc86b0310 100644 (file)
@@ -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)) {