Load user objects after readValue
authorOlaf Braun <info@braun-development.de>
Mon, 27 Nov 2023 07:12:41 +0000 (08:12 +0100)
committerOlaf Braun <info@braun-development.de>
Mon, 27 Nov 2023 07:12:41 +0000 (08:12 +0100)
wcfsetup/install/files/lib/system/form/builder/field/user/UserFormField.class.php

index dab747414dfb68b08ce5947a7c966349e95123d9..01928f8571786ac941918adfda4970e418314345 100644 (file)
@@ -119,9 +119,21 @@ final class UserFormField extends AbstractFormField implements
 
             if (\is_string($value)) {
                 if ($this->allowsMultiple()) {
-                    $this->value = ArrayUtil::trim(\explode(',', $value));
+                    $usernames = ArrayUtil::trim(\explode(',', $value));
+
+                    $this->users = \array_values(\array_filter(
+                        UserProfile::getUserProfilesByUsername($usernames),
+                        static function (?UserProfile $user) {
+                            return $user !== null;
+                        }
+                    ));
+                    $this->value = \array_column($this->users, 'username');
                 } else {
-                    $this->value = StringUtil::trim($value);
+                    $username = StringUtil::trim($value);
+                    $user = UserProfile::getUserProfileByUsername($username);
+                    $this->users = $user !== null ? [$user] : [];
+
+                    $this->value = $user?->username;
                 }
             }
         }