From: Junaid P V <junu.pv@gmail.com>

Fix issue #2423057

It targets issue of not passing user roles in MailChimp mergefield to MailChimp. As user roles field is multivalue filed, it does not get passed, though it is just integer array. With this fix, we convert array values to string by token replacement.


diff --git a/modules/mailchimp_lists/mailchimp_lists.module b/modules/mailchimp_lists/mailchimp_lists.module
index adf5806..d56fd6c 100644
--- a/modules/mailchimp_lists/mailchimp_lists.module
+++ b/modules/mailchimp_lists/mailchimp_lists.module
@@ -383,6 +383,16 @@ function _mailchimp_lists_mergevars_populate($mergefields, $entity, $entity_type
         $object = $object->{$element};
       }
       $mergevars[$label] = isset($object) ? $object->value() : NULL;
+      if (is_array($mergevars[$label])) {
+        // Array values cannot be passed to to MailChimp. So, convert it to
+        // single value using token replacement.
+        // This fix is mainly targetting to convert user roles array (which
+        // ontain array of integers) to comma seperated role names.
+        $replaced = token_generate($entity_type, array($property => $label), array($entity_type => $entity));
+        if (isset($replaced[$label])) {
+          $mergevars[$label] = $replaced[$label];
+        }
+      }
     }
   }
   drupal_alter('mailchimp_lists_mergevars', $mergevars, $entity, $entity_type);
