Problem/Motivation
In de mail mailchimp.module file the function mailchimp_subscribe() calls the function mailchimp_subscribe_process() to process the subscription.
When looking at the signature of mailchimp_subscribe(), the last argument ($tags) expects an array as the default value of $tags = [] suggests. When calling the function with an array as the argument for $tags, this results in an array to string conversion error. This is because mailchimp_subscribe() calls mailchimp_subscribe_process() and that function expects a string as the argument for $tags.
Tags are handled in mailchimp_subscribe_process() by exploding the argument variable supplied (line 537):
// Add or update member tags.
if ($tags) {
$tags = explode(',', (string) $tags);
$tags = array_map('trim', $tags);
If the $tags argument should be an array the function signatures should be changed along with the code above (and probably some calling code?). Turning $tags an array could make for a better developer experience, but is certainly not necessary as we can already process multiple tags with the current code by supplying a single string with comma-separated tags in it.
Steps to reproduce
Call the function mailchimp_subscribe() with an array as the argument for $tags and observe the resulting array to string conversion error.
Proposed resolution
Align the signatures of the functions mailchimp_subscribe() and mailchimp_subscribe_process():
function mailchimp_subscribe_process($list_id, $email, $merge_vars = NULL, $interests = [], $double_optin = FALSE, $format = 'html', $language = NULL, $gdpr_consent = FALSE, $tags = NULL) {
Use this signature for the mailchimp_subscribe() function (change $tags = [] to $tags = NULL) as such:
function mailchimp_subscribe($list_id, $email, $merge_vars = NULL, $interests = [], $double_optin = FALSE, $format = 'html', $language = NULL, $gdpr_consent = FALSE, $tags = NULL) {
Remaining tasks
Commit the patch supplied.
The issue
https://www.drupal.org/project/mailchimp/issues/3343846
๐
Update mailchimp_update_member_process for $tags
Active
also touches on this. The function mailchimp_update_member() discussed there also uses $tags = [] in the signature, it seems important to make a clear choice to avoid confusion and errors.
User interface changes
None.
API changes
None.
Data model changes
None.