After upgrading the MailChimp module from 7.x-3.x to 7.x-4.x (and the API library), this PHP warning appears after creating or updating a user account:
Warning: Invalid argument supplied for foreach() in mailchimp_lists_process_subscribe_form_choices() (line 264 of /srv/bindings/fb51db2c21174e7bacb47f0744f58f26/code/sites/all/modules/mailchimp/modules/mailchimp_lists/mailchimp_lists.module).
The code in question is this:
$interest_groups = (isset($choices['interest_groups'])) ? $choices['interest_groups'] : array();
dpm($interest_groups); // I added this
// Parse interests from interest groups.
$interests = array();
foreach ($interest_groups as $interest_group) {
foreach ($interest_group as $interest_id => $interest_status) { // this is line 264
$interests[$interest_id] = ($interest_status !== 0);
}
}
On my site the subscription field uses interest groups, and the user may only select one of them (they're radio buttons).
dpm()
reports this:
... (Array, 1 element)
dba908573b (String, 10 characters ) a0ebfb5959
I don't know this module well enough to know if line 264 is supposed to always expect an array instead of a string or if this is oversight, but in the case of my site line 264 is trying to process a string as an array.
I added debug output to mailchimp_update_member_process()
in mailchimp.module
for $merge_vars
and $interests
, and $merge_vars
has all the data it's supposed to have, but $interests
is an empty array.
Meanwhile in the system log every instance of the error message above is followed by this:
[redacted email address] was updated in list caaa257849_id.
That message is sort-of accurate and sort-of inaccurate because the $merge_vars
stuff still works but $interests
does not.
I tried the latest development release and the error message still happens.
Comment | File | Size | Author |
---|---|---|---|
#16 | invalid_argument-2838871-16.patch | 845 bytes | lukedekker |
#12 | mailchimp-fixing-interest-groups-with-new-subscribers-2838871-12.patch | 4.23 KB | Lord Pachelbel |
#7 | Drupal Mailchimp stuff.zip | 2.05 MB | Lord Pachelbel |
Comments
Comment #2
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedComment #3
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedFor now I'm patching it with this:
I'm not submitting a patch file because I suspect any fix for https://www.drupal.org/node/2530626 will affect the code above because they're closely related issues.
From my tracing through the code it seems to me that the main problem is inconsistent handling of
['#default_value']
pertaining to interest groups. In some cases['#default_value']
stores an interest group ID (a string), in some cases it stores an array of interest group IDs, and inmailchimp_interest_groups_form_elements()
it stores a two-dimensional array (an array of arrays of interest group IDs).I spent a few hours today trying to straighten it all out, but it's one of those problems in which every little fix I try breaks something else because of the inconsistencies with
['#default_value']
.Comment #4
johnpicozzi@Lord Pachelbel - I tried the code above and got the following offset error.
Illegal offset type in mailchimp_lists_process_subscribe_form_choices() (line 264 of /Users/johnpicozzi/Sites/leica/docroot/sites/all/modules/contrib/mailchimp/modules/mailchimp_lists/mailchimp_lists.module).
Comment #5
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedI'm using 7.x-4.7+1-dev if that helps.
Comment #6
nlarow CreditAttribution: nlarow as a volunteer commented@Lord Pachelbel I can't seem to get the older +1 dev version off of the repository or drush, it's up to +3. Any advice on getting the older version? I wanted to test your patch with that +1 branch, still trying to beat this problem.. I sent you an email yesterday with my contact info if needed. Thanks!
Comment #7
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedThis zip file contains the module and library I'm using.
Comment #8
nlarow CreditAttribution: nlarow as a volunteer commentedThank you! Appreciated
Comment #9
lukedekker CreditAttribution: lukedekker commentedI'm getting the same issue, but in the MailChimp module itself.
Warning: Invalid argument supplied for foreach() in mailchimp_update_local_cache() (line 607 ...
Started happening after upgrade from 3.x.
Comment #10
nlarow CreditAttribution: nlarow as a volunteer commented@Lord Pachabel, thank you but no luck.. Still the same error signing up new subscribers that are not on the list already.. Patching existing subscribers works ok, unsub/deletion seems to be working.. just new subscribers seem to fail on the "Interest Areas" ~
Same results with yesterday's dev release.. seems this is still an ongoing issue :( MailChimp's API log:
Even though the Drupal error log refers to an invalid ADDRESS merge field, it's actually the "Interest Areas" string/array that craps out the new subscriber process. The error reporting is incorrect, patching existing subscribers will merge all those fields properly, but will not deal with the Interest Areas correctly. And no it's not a blocked/testing account:
Comment #11
nlarow CreditAttribution: nlarow as a volunteer commentedFYI, I just rolled back to 7.x-3.6 today to alleviate the issue until it's corrected in the 4.x. A simple module/library replace + flush cache and it's signing up new members fine now in depreciated v2.0 mode.. should hold us over until they make more progress with this module. If anyone needs the old library (it's not on the repository anymore) for 7.x-3.6 just let me know.
Comment #12
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedI think I have it working (using 7.x-4.8+1-dev). This patch relies on the interest group caching patch at https://www.drupal.org/node/2835243#comment-11824409
Other patches you will probably want to use:
https://www.drupal.org/node/2831012
https://www.drupal.org/node/2530626#comment-11980729
Comment #13
lukedekker CreditAttribution: lukedekker commentedAdding another patch for the issue reported in #9.
Comment #14
lukedekker CreditAttribution: lukedekker commentedOops. Last patch was relative to the wrong directory.
Comment #15
lukedekker CreditAttribution: lukedekker commentedGosh. Didn't fix it properly last time. Sorry guys.
Comment #16
lukedekker CreditAttribution: lukedekker commentedI really need to test my patch before uploading.... Sorry again.
Comment #19
rjacobsen0 CreditAttribution: rjacobsen0 at ThinkShout for Mailchimp commentedCrediting from a duplicate issue.
Comment #22
rjacobsen0 CreditAttribution: rjacobsen0 at ThinkShout for Mailchimp commentedCommitting. You can see more discussion on this duplicate issue https://www.drupal.org/project/mailchimp/issues/2857646#comment-12902305. Thank you everyone!
Comment #24
entrepreneur27 CreditAttribution: entrepreneur27 commentedHi: I have Mailchimp 7.x-5.4 and seem to still have this issue so I am reopening it.
To be specific: I have several interest groups, and one of them has radio buttons. When I try and change the radio button interest group I get the error message below, and the interest group I elected is not saved.
Any ideas?
Warning: Invalid argument supplied for foreach() in _mailchimp_lists_field_postsave() (line 698 of /srv/bindings/fbca292e623a4b9caf138d968951b5b3/code/sites/all/modules/contrib/mailchimp/modules/mailchimp_lists/includes/mailchimp_lists.field.inc).
Warning: Invalid argument supplied for foreach() in mailchimp_lists_process_subscribe_form_choices() (line 265 of /srv/bindings/fbca292e623a4b9caf138d968951b5b3/code/sites/all/modules/contrib/mailchimp/modules/mailchimp_lists/mailchimp_lists.module).
Comment #25
drummThis fix does not look quite correct.
As an array key,
$interest_group
will never be an array, so that if statement will never be true.Comment #26
drummI re-opened #2857646: Warning: Invalid argument supplied for foreach() in mailchimp_update_local_cache(), since the patch there has a better if condition.