Problem/Motivation

When you create a Campaign from within Drupal you will get the following error if you do not have any Audience tags defined for your audience in Mailchimp.

TypeError: Argument 1 passed to Drupal\mailchimp_campaign\Form\MailchimpCampaignForm::parseTemplateContent() must be of the type array, null given, called in C:\Users\..\mailchimp\web\modules\contrib\mailchimp\modules\mailchimp_campaign\src\Form\MailchimpCampaignForm.php on line 417 in Drupal\mailchimp_campaign\Form\MailchimpCampaignForm->parseTemplateContent() (line 794 of C:\Users\..\web\modules\contrib\mailchimp\modules\mailchimp_campaign\src\Form\MailchimpCampaignForm.php)

It seems it's because I have no Audience Tags defined in Mailchimp. Because of this, I cannot select any Audience Tags in the admin/config/services/mailchimp/campaigns/add

If you create at least 1 Audience Tag in Mailchimp (even if you do not use it) the error goes away. I think the function parseTemplateContent needs to be updated to cater for non-existent Audience Tags.

This error might be related to #3044213: Campaign Templates - PHP Error Warning: array_keys() & Warning: Invalid argument

Because of this error, I am not able to create a Campaign from within Drupal, so I am setting this status to "Critical".

Steps to reproduce

1. Install the Mailchimp Campaign module.
2. In Mailchimp, create your audience but do not create any Audience Tags
3. Try creating a Campaign within Drupal (notice the Audience Tag field is blank)
4. You get WSOD

Temporary Solution

Create at least 1 Audience Tag in Mailchimp for your audience (even if you do not use it) and the error goes away.

Comments

xamount created an issue. See original summary.

spncr’s picture

Assigned: Unassigned » spncr
Status: Active » Closed (duplicate)

Thank you for reporting this!

I did some experimentation, and the steps you gave did not cause an error on their own.

The error you've pasted is coming from the preview function.

After some more testing, the only way I could reproduce it was to choose a template *without* any content areas, which matches what the error is stating - there is no content coming from the template to preview.

Content areas are defined in Mailchimp Templates, with this mc:edit property:
https://templates.mailchimp.com/getting-started/template-language/

If you go back and add this to one of your custom templates, you might have to clear your drupal cache (drush cr) for the new template to be fetched.

The goal of this Mailchimp campaign module is to allow you to embed content from your Drupal site into the content of a Mailchimp campaign template. That means there isn't really a reason, that I can imagine, to use this module with a template without any content areas.

I agree that we should make the error more explicit and not let it crash the site entirely, and will work on a fix in the linked issue:
https://www.drupal.org/project/mailchimp/issues/3044213

If I misunderstood anything, please let me know and I will have another look!