Skip to content

Commit

Permalink
pkp#10489 Allow users to add custom initials for avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Nov 26, 2024
1 parent 43eced2 commit d858b7a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
17 changes: 17 additions & 0 deletions classes/identity/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.).
*
Expand Down
6 changes: 4 additions & 2 deletions classes/user/form/IdentityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function initData()
'familyName' => $user->getFamilyName(null),
'preferredPublicName' => $user->getPreferredPublicName(null),
'orcid' => $user->getOrcid(),
'preferredAvatarInitials' => $user->getPreferredAvatarInitials(null),
];
}

Expand All @@ -109,7 +110,7 @@ public function readInputData()
parent::readInputData();

$this->readUserVars([
'givenName', 'familyName', 'preferredPublicName', 'orcid','removeOrcidId'
'givenName', 'familyName', 'preferredPublicName', 'orcid', 'removeOrcidId', 'preferredAvatarInitials'
]);
}

Expand All @@ -123,14 +124,15 @@ 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);
} else {
$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);
Expand Down
7 changes: 7 additions & 0 deletions locale/en/user.po
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
9 changes: 9 additions & 0 deletions schemas/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions templates/user/identityForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}

<div class="orcid_container">
Expand Down

0 comments on commit d858b7a

Please sign in to comment.