I need to use the "Mirror RedHen Contact email to Drupal user" setting so that email addresses between the contact and user accounts stay in sync when a user updates his Redhen account. But I don't want the contact email overwritten when I link the accounts. Instead, I need the email from the newly created user account to supersede the email in the contact's account, since most likely, the contact record hasn't been updated in months or years. So, I wrote a patch that adds the user's email to the contact's account as the primary email. I also created a Redhen setting that turns the feature on and off. Feedback welcome on better coding practices!
Mickey
Comment | File | Size | Author |
---|---|---|---|
#3 | redhen_contacts-linking_accounts_email-2039145-3.patch | 2.4 KB | micnap |
#2 | redhen_contacts-linking_accounts_email-2039145-2.patch | 2.4 KB | micnap |
redhen_contacts-linking_accounts_email-1.patch | 2.02 KB | micnap | |
Comments
Comment #1
micnap CreditAttribution: micnap commentedCorrection: But I don't want the user email overwritten when I link the accounts
Comment #2
micnap CreditAttribution: micnap commentedAttempt #2. Works when contact has no emails now (oops!). But only works if 'Connect users to Redhen contacts' setting is turned off. Otherwise, if a contact is saved and automatic linking occurs, the user email will still be overwritten with the contact email. Don't know if it's possible to determine who is updating the contact form (user or admin) or where the form is being saved (url) to conditionally prevent the user email from being overwritten. If not, the a check to the Redhen settings form is probably needed - if 'Add contact email to user being linked to' is checked, then 'Connect users to Redhen contacts' must be unchecked.
Comment #3
micnap CreditAttribution: micnap commentedBlurgh. Typo.
Comment #4
seanberto CreditAttribution: seanberto commentedHah, stumbled into this issue on my own in #2047741: Better form/validation handling for RedHen settings associated with Drupal user accounts.. Nice catch, Micnap!
Comment #5
seanberto CreditAttribution: seanberto commentedHeya Micnap, do you mind testing this patch against the dev release? There were some recent changes to the way that RedHen emails are stored. I don't think that it will break your patch, but it'd be helpful if you had a bit of time to retest.
Comment #6
micnap CreditAttribution: micnap commentedYup! Will do!
Comment #7
micnap CreditAttribution: micnap commentedJust gave the patch a thorough testing with the dev version. Tested every scenario I could think of (contact with 0 email addresses, 1 address, multiple addresses, etc.) and it still worked. When the user is linked with the contact, the user email address becomes primary in the contact account and any other contact emails remain but are unset as primary. Updating the contact email address after they're linked also still updates the user email address. Yay!