From d858b7a7fc6518c9beff68e2997ad83d81c2681f Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 26 Nov 2024 18:34:45 -0500 Subject: [PATCH] pkp/pkp-lib#10489 Allow users to add custom initials for avatars --- classes/identity/Identity.php | 17 +++++++++++++++++ classes/user/form/IdentityForm.php | 6 ++++-- locale/en/user.po | 7 +++++++ schemas/user.json | 9 +++++++++ templates/user/identityForm.tpl | 5 +++++ 5 files changed, 42 insertions(+), 2 deletions(-) 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..49f6e682e8f 100644 --- a/classes/user/form/IdentityForm.php +++ b/classes/user/form/IdentityForm.php @@ -98,6 +98,7 @@ public function initData() 'familyName' => $user->getFamilyName(null), 'preferredPublicName' => $user->getPreferredPublicName(null), 'orcid' => $user->getOrcid(), + 'preferredAvatarInitials' => $user->getPreferredAvatarInitials(null), ]; } @@ -109,7 +110,7 @@ public function readInputData() parent::readInputData(); $this->readUserVars([ - 'givenName', 'familyName', 'preferredPublicName', 'orcid','removeOrcidId' + 'givenName', 'familyName', 'preferredPublicName', 'orcid', 'removeOrcidId', 'preferredAvatarInitials' ]); } @@ -123,7 +124,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 +132,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($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..5166b76f66e 100644 --- a/schemas/user.json +++ b/schemas/user.json @@ -217,6 +217,15 @@ "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" + ] + }, "signature": { "type": "string", "multilingual": true, diff --git a/templates/user/identityForm.tpl b/templates/user/identityForm.tpl index 3ae4e9be939..1631104c7d1 100644 --- a/templates/user/identityForm.tpl +++ b/templates/user/identityForm.tpl @@ -50,6 +50,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="preferredPublicName" value=$preferredAvatarInitials size=$fbvStyles.size.SMALL} + {/fbvFormSection} + {if $orcidEnabled}