Skip to content

Syncing first/last name fields on an existing user without a fullName mapping will not update fullName #32

@Braedan

Description

@Braedan

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

  1. Set populateProfile and syncProfile to true in social settings
  2. 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)
  3. Log in via SSO to any provider that has fieldMapping for firstName and lastName but not fullName (eg; Google provider)
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions