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.
Hi all!
If I'm using interest groups than when I'm subscribing to a mailchimp list than a warning returned:
Warning: Invalid argument supplied for foreach() mailchimp_signup_subscribe_form_submit() függvényben (/home/shl/public_html/sites/all/modules/contrib/mailchimp/modules/mailchimp_signup/mailchimp_signup.module 386 sor).
It's caused by a foreach in mailchimp_signup_subscribe_form_submit():
foreach ($interest_groups as $interest_group) {
dsm($interest_group); // <--- custom debugging
foreach ($interest_group as $interest_id => $interest_status) {
$interests[$interest_id] = ($interest_status !== 0);
}
}
dsm() prints $interest_group, but it is not an array only a string
this workaround solves the problem for me:
function MYMODULE_form_mailchimp_signup_subscribe_block_newsletter_form_alter(&$form, &$form_state, $form_id) {
...
$form['#validate'][] = 'MYMODULE_form_mailchimp_signup_subscribe_block_newsletter_form_validate';
}
function MYMODULE_form_mailchimp_signup_subscribe_block_newsletter_form_validate($form, &$form_state) {
if (
isset($form_state['values']['mailchimp_lists']['interest_groups']) &&
!empty($form_state['values']['mailchimp_lists']['interest_groups'])
) {
foreach ($form_state['values']['mailchimp_lists']['interest_groups'] as $ig_key => $ig) {
$form_state['values']['mailchimp_lists']['interest_groups'][$ig_key] = array($ig => 1);
}
}
}
mailchimp version: 7.x-4.7+1-dev
Comments
Comment #2
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedI'm flagging some related issues. Ultimately the problem seems to be that the code that handles interest groups is written inconsistently throughout the module.
See https://www.drupal.org/node/2838871#comment-11840831 for my analysis and why I stopped trying (for now) to make a comprehensive solution.
Comment #3
Lord Pachelbel CreditAttribution: Lord Pachelbel commentedComment #4
samuel.mortensonThe related issue, #2838871: "Invalid argument supplied for foreach() in mailchimp_lists_process_subscribe_form_choices()" error prevents interest group subscriptions/updates, seems to resolve this problem.