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

fox mulder created an issue. See original summary.

Lord Pachelbel’s picture

I'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.

Lord Pachelbel’s picture

samuel.mortenson’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.