Describe the bug
When syncing an existing user profile, if fullName is set and there's no mapping set on the provider (which is the case for Google, and likely others), it can fall out of sync with the firstName and lastName fields.
Craft handles this on User::afterSave via NameTrait::prepareNamesForSave(), but As of 4.9 only if fullName or first/last name is null.
(Sorry in advance if this should be a feature request; its hard to tell what the expected behaviour should be)
Steps to reproduce
- Set
populateProfile and syncProfile to true in social settings
- Create a user that will share an email with an SSO login, set Full Name to
fName lName (assuming SSO first/last name isn't the same)
- Log in via SSO to any provider that has
fieldMapping for firstName and lastName but not fullName (eg; Google provider)
- Updated User element will save, but Full Name will not be synced with new first name / last name values
Craft CMS version
4.9.5
Plugin version
1.0.15
Multi-site?
No
Additional context
To fix, could use User::setAttributes() instead of manually assigning values onto the user object in services\Users::_syncUserProfile(). The function handles firstName / lastName logic (see: https://github.com/craftcms/cms/blob/5.x/src/elements/User.php#L995-L1006).
Alternatively, adding an event onto _syncUserProfile where I could manually set fullName = null would be handy, as right now I'm resolving by emulating the setAttributes conditional on User::EVENT_BEFORE_SAVE
Describe the bug
When syncing an existing user profile, if
fullNameis set and there's no mapping set on the provider (which is the case for Google, and likely others), it can fall out of sync with thefirstNameandlastNamefields.Craft handles this on
User::afterSaveviaNameTrait::prepareNamesForSave(), but As of 4.9 only iffullNameor first/last name is null.(Sorry in advance if this should be a feature request; its hard to tell what the expected behaviour should be)
Steps to reproduce
populateProfileandsyncProfiletotruein social settingsfName lName(assuming SSO first/last name isn't the same)fieldMappingforfirstNameandlastNamebut notfullName(eg; Google provider)Craft CMS version
4.9.5
Plugin version
1.0.15
Multi-site?
No
Additional context
To fix, could use
User::setAttributes()instead of manually assigning values onto the user object inservices\Users::_syncUserProfile(). The function handlesfirstName/lastNamelogic (see: https://github.com/craftcms/cms/blob/5.x/src/elements/User.php#L995-L1006).Alternatively, adding an event onto
_syncUserProfilewhere I could manually setfullName = nullwould be handy, as right now I'm resolving by emulating the setAttributes conditional onUser::EVENT_BEFORE_SAVE