-
-
Notifications
You must be signed in to change notification settings - Fork 6
Syncing first/last name fields on an existing user without a fullName mapping will not update fullName #32
Description
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
populateProfileandsyncProfiletotruein 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
fieldMappingforfirstNameandlastNamebut notfullName(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