Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The issue right now is when you save your profile fields, it syncs the previous values with mailchimp which means you essentially have to save the user page twice. I patched it with 'after_update' and it works just fine.
Comment | File | Size | Author |
---|---|---|---|
#5 | mailchimp.module.patch | 1.61 KB | kanani |
#4 | mailchimp.module.patch | 1.25 KB | kanani |
Comments
Comment #1
levelos CreditAttribution: levelos commentedhttp://drupal.org/commitlog/commit/5104/6b1393a4aa177e54d00c7fb91a2ee2e2...
Comment #2
kanani CreditAttribution: kanani commentedSo changing hook_user to fire on 'after_update' causes an issue when a user is trying to change their email address.
On 'update' the old email address is preserved in $account->mail and the new email is stored in $edit['mail'] so that listUpdateMember is called, mailchimp has a valid key to work against to pass in the new email in the merge_vars.
If hook_user is fired on 'after_update', $account->mail and $edit['mail'] both contain the new email so instead of the old getting set to new, a new subscriber is added to the list in mailchimp, and the old one is retained.
In addition to having the user subscribed twice (albeit with different email addresses), this makes it impossible to delete the original email from mailchimp through Drupal because any calls to listUnsubscribe will use the old email as a key.
Maybe a workaround to this would be to have fire hook_user on 'update' but only let it update mail, then the rest of the updates can occur on 'after_update'?
Comment #3
kanani CreditAttribution: kanani commentedComment #4
kanani CreditAttribution: kanani commentedPatch to check email on update, everything else on after_update. Also make sense to revisit whether this should fire on $op == 'update'
Comment #5
kanani CreditAttribution: kanani commentedPrevious patch didn't include 'update' check in if in_array check.
Comment #6
bleedev CreditAttribution: bleedev commentedCommitted change to pass updated email to to use in 'after_update'.