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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

micnap’s picture

Correction: But I don't want the user email overwritten when I link the accounts

micnap’s picture

Attempt #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.

micnap’s picture

seanberto’s picture

seanberto’s picture

Version: 7.x-1.3 » 7.x-1.x-dev

Heya 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.

micnap’s picture

Yup! Will do!

micnap’s picture

Status: Active » Needs review

Just 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!