I am getting two PHP errors when selecting a campaign template to use. These are resulting in no content sections being rendered in the Content Sections Field. When no template selected I have 1 content section available.

I have not found a similar issue. Could this be a configuration problem?

PHP Errors:
Warning: arra to be array, null given in Drupal\mailchimp_campaign\Form\MailchimpCampaignForm->parseTemplateContent() (line 678 ... /mailchimp/modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php)

Warning: Invalid argument supplied for foreach() in Drupal\mailchimp_campaign\Form\MailchimpCampaignForm->parseTemplateContent() (line 679 of ... /mailchimp/modules/mailchimp_campaign/src/Form/MailchimpCampaignForm.php)

MailchimpCampaignForm.php Function

private function parseTemplateContent($content) {
    $template_content = array();
    $content_keys = array_keys($content);
    foreach ($content_keys as $content_key) {
      if (strpos($content_key, '_wrapper') !== FALSE) {
        // If this element is a wrapper, add the element contained
        // within the wrapper to the template content.
        $new_content_key = str_replace('_wrapper', '', $content_key);
        $template_content[$new_content_key] = $content[$content_key][$new_content_key];
      }
      else {
        // If this element is not a wrapper, add it to the template content.
        $template_content[$content_key] = $content[$content_key];
      }
    }
    return $template_content;
  }

I am not sure if this is related to the problem but when I select the Templates drop down I have three sections: My Custom Templates (All Templates Available), base (with Accept Payments, Lead Generation and some others), and Themes (with what seems to be 10 random chosen themes). This could be normal module function.

Comments

DrupalRanger created an issue. See original summary.

baikho’s picture

Issue summary: View changes
baikho’s picture

Assigned: Unassigned » baikho
baikho’s picture

Assigned: baikho » Unassigned
Status: Active » Needs review
StatusFileSize
new692 bytes

See added patch for both warnings

DrupalRanger’s picture

This patch works, the PHP errors do not occur.

However, the problem still exists.
No Regions in the Content Section are being rendered when I select a template. I realized I was using PHP V 7.0.33 thus I upgraded to 7.1.27. Still not working.

Update: I created a brand new mailchimp account, created a new API key, created a new mailchimp campaign. When choosing Template I had two lists of 10 items each, base and Themes. (The 10 seem randomly chosen and different from my original account). Only a few of the base items had regions that populated in the Content Section. Specifically Shipping Confirmation did. None of the Themes listed had Content Section Regions. Given this I think there may be an API call problem.

Mailchimp API
GET /templates
count Type:Integer Title:Count Read only:true The number of records to return. Default value is 10.

Thoughts?

baikho’s picture

Status: Needs review » Needs work

Hmm not sure. I'll see If I can find some time later to fix this. Updating status for now.

jvr968’s picture

Hello,
I have a similar problem
I have no errors but there are no content sections shown to add content in the template.
I only see base and themes templates, and in the base templates, Accept Payments and Lead Generation are being shown several times.
I'm only able to add content when there is no template selected.

I am using PHP 7.2.32

php -v
PHP 7.2.32 (cli) (built: Jul 8 2020 07:33:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.32, Copyright (c) 1999-2018, by Zend Technologies

Which is the problem?
Thank you
Regards.

jfranzen’s picture

Also having the same problem.
The patch made the error message go away, and only the Shipping Confirmation template populates the content section.
Are all users of the 8.x version creating their content through the Mailchimp service?

bart lambert’s picture

+1

gcb’s picture

Component: General » Campaign Module
Assigned: Unassigned » aprice42
gcb’s picture

Assigned: aprice42 » wxactly
gcb’s picture

Assigned: wxactly » itrebecca
spncr’s picture

Version: 8.x-1.x-dev » 2.x-dev
Assigned: itrebecca » spncr
StatusFileSize
new1.52 KB

The php error is definitely a problem, but @baikho has the right idea to circumvent the crash.

I've attached a patch that is slightly more helpful, because it shows a warning.

If your goal is to make a Mailchimp campaign that includes Drupal entities/content, then you first need to create a Mailchimp email template that has editable areas:
https://templates.mailchimp.com/getting-started/template-language/

In my testing, I had to clear my Drupal cache after updating the template, before the new content areas showed up.

These editable areas are what populate the editable content sections in this Drupal module.

If someone on this thread has a different use case or goal please let me know so we can consider it.

I'm going to think on this a bit more, I'd like to see the error be field specific and perhaps even not list any templates UNLESS they have 1 or more editable content areas.

If you have a situation where you definitely want to use a template through Drupal without any editable areas, please let me know what the use case is!

  • gcb committed 10e3f5e on 2.x authored by spncr
    Issue #3044213 by baikho, spncr: Campaign Templates - PHP Error Warning...
gcb’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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