UserFormField returned no values if required flag was set
authorMarcel Werk <burntime@woltlab.com>
Sat, 15 Feb 2020 14:52:07 +0000 (15:52 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sat, 15 Feb 2020 14:52:07 +0000 (15:52 +0100)
wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php

index e1b34c1919f76cd70f50fcabc5aee2efc86b0310..530d5146b75c56e9f26185771fa0dfd94001ba21 100644 (file)
@@ -129,63 +129,62 @@ class UserFormField extends AbstractFormField implements IAutoFocusFormField, II
                ) {
                        $this->addValidationError(new FormFieldValidationError('empty'));
                }
-               else if (!$this->isRequired()) {
-                       if ($this->allowsMultiple()) {
-                               if ($this->getMinimumMultiples() > 0 && count($this->getValue()) < $this->getMinimumMultiples()) {
-                                       $this->addValidationError(new FormFieldValidationError(
-                                               'minimumMultiples',
-                                               'wcf.form.field.user.error.minimumMultiples',
-                                               [
-                                                       'minimumCount' => $this->getMinimumMultiples(),
-                                                       'count' => count($this->getValue())
-                                               ]
-                                       ));
-                               }
-                               else if ($this->getMaximumMultiples() !== IMultipleFormField::NO_MAXIMUM_MULTIPLES && count($this->getValue()) > $this->getMaximumMultiples()) {
-                                       $this->addValidationError(new FormFieldValidationError(
-                                               'maximumMultiples',
-                                               'wcf.form.field.user.error.maximumMultiples',
-                                               [
-                                                       'maximumCount' => $this->getMaximumMultiples(),
-                                                       'count' => count($this->getValue())
-                                               ]
-                                       ));
-                               }
-                               else {
-                                       // validate users
-                                       $this->users = UserProfile::getUserProfilesByUsername($this->getValue());
-                                       
-                                       $nonExistentUsernames = [];
-                                       foreach ($this->getValue() as $username) {
-                                               if (!isset($this->users[$username])) {
-                                                       $nonExistentUsernames[] = $username;
-                                               }
-                                       }
-                                       
-                                       if (!empty($nonExistentUsernames)) {
-                                               $this->addValidationError(new FormFieldValidationError(
-                                                       'nonExistent',
-                                                       'wcf.form.field.user.error.nonExistent',
-                                                       ['nonExistentUsernames' => $nonExistentUsernames]
-                                               ));
+               
+               if ($this->allowsMultiple()) {
+                       if ($this->getMinimumMultiples() > 0 && count($this->getValue()) < $this->getMinimumMultiples()) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'minimumMultiples',
+                                       'wcf.form.field.user.error.minimumMultiples',
+                                       [
+                                               'minimumCount' => $this->getMinimumMultiples(),
+                                               'count' => count($this->getValue())
+                                       ]
+                               ));
+                       }
+                       else if ($this->getMaximumMultiples() !== IMultipleFormField::NO_MAXIMUM_MULTIPLES && count($this->getValue()) > $this->getMaximumMultiples()) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'maximumMultiples',
+                                       'wcf.form.field.user.error.maximumMultiples',
+                                       [
+                                               'maximumCount' => $this->getMaximumMultiples(),
+                                               'count' => count($this->getValue())
+                                       ]
+                               ));
+                       }
+                       else {
+                               // validate users
+                               $this->users = UserProfile::getUserProfilesByUsername($this->getValue());
+                               
+                               $nonExistentUsernames = [];
+                               foreach ($this->getValue() as $username) {
+                                       if (!isset($this->users[$username])) {
+                                               $nonExistentUsernames[] = $username;
                                        }
                                }
-                       }
-                       else if ($this->getValue() !== '') {
-                               $user = UserProfile::getUserProfileByUsername($this->getValue());
                                
-                               if ($user === null) {
+                               if (!empty($nonExistentUsernames)) {
                                        $this->addValidationError(new FormFieldValidationError(
                                                'nonExistent',
-                                               'wcf.form.field.user.error.invalid'
+                                               'wcf.form.field.user.error.nonExistent',
+                                               ['nonExistentUsernames' => $nonExistentUsernames]
                                        ));
                                }
-                               else {
-                                       $this->users[] = $user;
-                               }
                        }
                }
-               
+               else if ($this->getValue() !== '') {
+                       $user = UserProfile::getUserProfileByUsername($this->getValue());
+                       
+                       if ($user === null) {
+                               $this->addValidationError(new FormFieldValidationError(
+                                       'nonExistent',
+                                       'wcf.form.field.user.error.invalid'
+                               ));
+                       }
+                       else {
+                               $this->users[] = $user;
+                       }
+               }
+                               
                parent::validate();
        }