diff --git a/classes/identity/Identity.php b/classes/identity/Identity.php index 522c5e4ee10..4c5ceedd27d 100644 --- a/classes/identity/Identity.php +++ b/classes/identity/Identity.php @@ -201,6 +201,23 @@ public function setPreferredPublicName($preferredPublicName, $locale) $this->setData('preferredPublicName', $preferredPublicName, $locale); } + + /** + * Set preferred avatar initials. + */ + public function setPreferredAvatarInitials(string $preferredAvatarInitials, ?string $locale): void + { + $this->setData('preferredAvatarInitials', $preferredAvatarInitials, $locale); + } + + /** + * Get preferred avatar initials. + */ + public function getPreferredAvatarInitials(?string $locale): ?string + { + return $this->getData('preferredAvatarInitials', $locale); + } + /** * Get affiliation (position, institution, etc.). * diff --git a/classes/user/form/IdentityForm.php b/classes/user/form/IdentityForm.php index f1e237b190b..0fc0da6348f 100644 --- a/classes/user/form/IdentityForm.php +++ b/classes/user/form/IdentityForm.php @@ -18,6 +18,7 @@ use APP\core\Application; use APP\template\TemplateManager; +use Illuminate\Support\Str; use PKP\orcid\OrcidManager; use PKP\user\User; @@ -98,6 +99,7 @@ public function initData() 'familyName' => $user->getFamilyName(null), 'preferredPublicName' => $user->getPreferredPublicName(null), 'orcid' => $user->getOrcid(), + 'preferredAvatarInitials' => $user->getPreferredAvatarInitials(null), ]; } @@ -109,7 +111,7 @@ public function readInputData() parent::readInputData(); $this->readUserVars([ - 'givenName', 'familyName', 'preferredPublicName', 'orcid','removeOrcidId' + 'givenName', 'familyName', 'preferredPublicName', 'orcid', 'removeOrcidId', 'preferredAvatarInitials' ]); } @@ -123,7 +125,7 @@ public function execute(...$functionArgs) // Request to delete ORCID token is handled separately from other form field updates - if($this->getData('removeOrcidId') === 'true') { + if ($this->getData('removeOrcidId') === 'true') { $user->setOrcid(null); $user->setOrcidVerified(false); OrcidManager::removeOrcidAccessToken($user); @@ -131,6 +133,7 @@ public function execute(...$functionArgs) $user->setGivenName($this->getData('givenName'), null); $user->setFamilyName($this->getData('familyName'), null); $user->setPreferredPublicName($this->getData('preferredPublicName'), null); + $user->setPreferredAvatarInitials(trim(Str::upper($this->getData('preferredAvatarInitials') ?? '')), null); } parent::execute(...$functionArgs); diff --git a/locale/en/user.po b/locale/en/user.po index 1d9a96a9848..3b4976478cf 100644 --- a/locale/en/user.po +++ b/locale/en/user.po @@ -239,6 +239,13 @@ msgstr "" "Please provide the full name as the author should be identified on the " "published work. Example: Dr. Alan P. Mwandenga" +msgid "user.preferredAvatarInitials" +msgstr "Preferred Avatar Initials" + +msgid "user.preferredAvatarInitials.description" +msgstr "" +"Enter the two letters you’d like to use as your avatar. These initials will be displayed to represent you." + msgid "user.profile.changePasswordInstructions" msgstr "" "Enter your current and new passwords below to change the password for your " diff --git a/schemas/user.json b/schemas/user.json index d10b7de76e8..57c5618fac2 100644 --- a/schemas/user.json +++ b/schemas/user.json @@ -217,6 +217,16 @@ "nullable" ] }, + "preferredAvatarInitials": { + "type": "string", + "description": "An optional field for users to specify the initials that they want to be displayed in their avatars.", + "multilingual": false, + "apiSummary": true, + "validation": [ + "nullable", + "max:2" + ] + }, "signature": { "type": "string", "multilingual": true, diff --git a/templates/user/identityForm.tpl b/templates/user/identityForm.tpl index 3ae4e9be939..b84046a5a8f 100644 --- a/templates/user/identityForm.tpl +++ b/templates/user/identityForm.tpl @@ -22,6 +22,13 @@ $('#removeOrcidId').remove(); } }); + + $(function() {ldelim} + $('input[name="preferredAvatarInitials"]').on('keyup', function() { + const capitalizedValue = $(this).val().toUpperCase().trim(); + $(this).val(capitalizedValue); + }); + {rdelim}); {rdelim}); @@ -42,7 +49,7 @@ {fbvFormArea id="userFormCompactLeft"} {fbvFormSection title="user.name"} {fbvElement type="text" label="user.givenName" multilingual="true" required="true" id="givenName" value=$givenName maxlength="255" inline=true size=$fbvStyles.size.MEDIUM} - {fbvElement type="text" label="user.familyName" multilingual="true" id="familyName" value=$familyName maxlength="255" inline=true size=$fbvStyles.size.MEDIUM} + {fbvElement type="text" label="user.familyName" multilingual="true" id="familyName" value=$familyName maxlength="255" inline=true size=$fbvStyles.size.MEDIUM onkeyup="this.value = this.value.toUpperCase();"} {/fbvFormSection} {/fbvFormArea} @@ -50,6 +57,11 @@ {fbvElement type="text" label="user.preferredPublicName" multilingual="true" name="preferredPublicName" id="preferredPublicName" value=$preferredPublicName size=$fbvStyles.size.LARGE} {/fbvFormSection} + + {fbvFormSection for="preferredAvatarInitials" description="user.preferredAvatarInitials.description"} + {fbvElement type="text" label="user.preferredAvatarInitials" name="preferredAvatarInitials" maxlength="2" id="preferredAvatarInitials" value=$preferredAvatarInitials size=$fbvStyles.size.SMALL} + {/fbvFormSection} + {if $orcidEnabled}