Problem/Motivation

I wanted to check a MailchimpListsSubscription Entity for the 'subscribed' value through using
$subscription->getSubscribe()
Strange enough it always returned NULL. Although the checkbox seemed to save the changes when I checked/unchecked it.

The problem was that, during building the form/widget, the code checked the DB first and immediatly after checks mailchimp for the subscription and sets the default value for the field.
mailchimp_d8/modules/mailchimp_lists/src/Plugin/Field/FieldWidget/MailchimpListsSelectWidget.php::formElement():33

    // Check the current Instance / read from DB
    $subscribe_default = $instance->getSubscribe();

    $email = NULL;
    if (!empty($instance->getEntity())) {
      $email = mailchimp_lists_load_email($instance, $instance->getEntity(), FALSE);
      if ($email) {
        // Check mailchimp itself
        $subscribe_default = mailchimp_is_subscribed($instance->getFieldDefinition()->getSetting('mc_list_id'), $email);
      }
    }

It is possible that there are 2 different states on Mailchimp and in the DB which should be checked for. But thats another problem.

The actual problem that getSubscribe() doesn't work is because of the extra ['value'] array dimension in several places, so the field in the DB never gets actually updated.

Proposed resolution

Using the ['values'] property of the Instance of the Class correctly.
Removing the extra ['value'] dimension where necessary.

Remaining tasks

I havent tested this thoroughly, but it doesn't seem like a big change.
Also, as seen in the patch, the property value ['interest_groups'] was affected. It threw an error at me while viewing the field settings of a 'Mailchimp Subscription' field. Not anymore.

User interface changes

API changes

Data model changes

Comments

vierlex created an issue. See original summary.

vierlex’s picture

StatusFileSize
new1.93 KB
vierlex’s picture

Priority: Normal » Major
Issue summary: View changes
vierlex’s picture

grienauer’s picture

Status: Active » Reviewed & tested by the community

Could a maintainer take a quick look at this issue please?
We use this patch at one site and it now works.

thx!

grienauer’s picture

Status: Reviewed & tested by the community » Active
khiminrm’s picture

I've updated patch for last stable version of Mailchimp (8.x-1.8).
Could it be committed, please?

khiminrm’s picture

Status: Active » Needs review
init90’s picture

Status: Needs review » Reviewed & tested by the community

We use the patch of one of our project for a long time and all works good.

sivaprasadc’s picture

@vierlex

Thanks for the patch, It works like a charm.

stephen ollman’s picture

Patched tested and works as advertised.

Many thanks!

When will this patch be rolled into the latest release?

rviner’s picture

Following on from this I also noticed you can no longer unsubscribe from a list. The allow_unsubscribe parameter is always False despite this being true in the settings.

rviner’s picture

Created a new issue for this: Can't unsubscribe from lists

samuel.mortenson’s picture

Assigned: Unassigned » aprice42
jtotheeannie’s picture

We've applied the patch on our site and its working wonderfully when extracting the subscription status from the database.

However when using a webhooks, the user unsubscribes through the mailchimp interface, the checkbox is unchecked on the Drupal side, but the database is then not updated to reflect that the user is unsubscribed.
If we re-save the user info then the database is updated, but it would be nice if it was updated automatically as opposed to re-checking the mailchimp cleaned list and re-saving all users individually.

mshaver’s picture

Assigned: aprice42 » samuel.mortenson

  • khiminrm authored b032d89 on 8.x-1.x
    Issue #2903853 by vierlex, khiminrm: MailchimpListsSubscription doesnt...
samuel.mortenson’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the fix all. @Jtotheeannie Could you open a follow up issue for that problem with replication steps? Thank you!

jtotheeannie’s picture

Status: Fixed » Closed (fixed)

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