The Mailchimp list field only provides coarse access to the subscription details: a setter and getter for the field value directly, but the subscription data actual contains structured data: a "subscription" boolean and an array of interest group preferences. The field should provide direct setters and getters for these as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gcb created an issue. See original summary.

gcb’s picture

wxactly’s picture

Here's a patch that provides sub-property getters and setters for "subscribed" and "interest groups" without going any deeper into the nested MailChimp API structure for the groups. This enables property access, like:

$entity->field->subscribe->value();
$entity->field->interest_groups->value();
wxactly’s picture

Updated patch. MailChimp's data structure was failing validation for the "list" type, so changed to "struct".

nlarow’s picture

Wxactly,

I've applied your more recent patch (I've tried and reverted all 3 in this topic to be honest..) and I was able to see the new token:variables exposed in "help/tokens".. but I'm running into a real problem actually using the new token for "field:interest_groups" in an email template as I cannot get it to output anything other than the word "Property".

Note that "field:subscribe" works and returns a true/false value... it's just the "field:interest_groups" that appear to not work..

Any input? Much appreciated.

Regards,
Nicholaus

nlarow’s picture

Priority: Normal » Major
wxactly’s picture

@nlarow - The data structure for interest groups is a complex multi-dimensional array. Unfortunately the simple patch I added here isn't going to help you very much for using interest groups in tokens. You'll need something more like what @gcb started in his first patch... though, as he noted, it needs some serious work. If someone wants to jump in and give it another shot, I think the first patch here is a decent starting point. I actually tried to jump in and add full nested support for the multi-dimensional data structure myself, but it was just getting too complicated so I scrapped it and went the simpler route instead.

ruscoe’s picture

Status: Needs work » Closed (won't fix)

We're going to be ending support for the 7.x-3.x branch due to the upcoming deprecation of the v2.0 MailChimp API. If you're still interested in this feature, please feel free to reopen for the 7.x-4.x branch.

wxactly’s picture

#4 is still relevant, so I re-rolled this patch. This is an easy win which adds sub-property getters and setters for "subscribed" boolean and "interest groups" struct:

$entity->field->subscribe->value();
$entity->field->interest_groups->value();
wxactly’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
Status: Closed (won't fix) » Needs review
samuel.mortenson’s picture

Status: Needs review » Closed (won't fix)

We’re in maintenance-mode for the Drupal 7 releases of Mailchimp, so only bug fixes can be committed going forward. Any new features should be developed for the Drupal 8 releases of Mailchimp. Thanks!