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 28, 2024
1 parent 8d8ada9 commit 75b1294
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 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
7 changes: 5 additions & 2 deletions classes/user/form/IdentityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use APP\core\Application;
use APP\template\TemplateManager;
use Illuminate\Support\Str;
use PKP\orcid\OrcidManager;
use PKP\user\User;

Expand Down Expand Up @@ -98,6 +99,7 @@ public function initData()
'familyName' => $user->getFamilyName(null),
'preferredPublicName' => $user->getPreferredPublicName(null),
'orcid' => $user->getOrcid(),
'preferredAvatarInitials' => $user->getPreferredAvatarInitials(null),
];
}

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

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

Expand All @@ -123,14 +125,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(trim(Str::upper($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
10 changes: 10 additions & 0 deletions schemas/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion templates/user/identityForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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});
</script>

Expand All @@ -42,14 +49,19 @@
{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}

{fbvFormSection for="preferredPublicName" description="user.preferredPublicName.description"}
{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}

<div class="orcid_container">
Expand Down Expand Up @@ -80,3 +92,8 @@

{fbvFormButtons hideCancel=true submitText="common.save"}
</form>


<script>
</script>

0 comments on commit 75b1294

Please sign in to comment.