Problem/Motivation

Lately we noticed that even if just a few interest groups have been selected in webform submit handlers, users are subscribed to all interest groups available.

mailchimp_subscribe_process() looks for enabled interst groups like:

foreach ($interests as $interest_group) {
  foreach ($interest_group as $interest_id => $interest_status) {
    $selected_interests[$interest_id] = ($interest_status !== 0);
  }
}

Currentlty webform mailchimp schema type for interest is string, making this always TRUE.

Proposed resolution

Filter out interest groups that have not been selected when saving the settings.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

Primsi created an issue. See original summary.

primsi’s picture

Status: Active » Needs review
StatusFileSize
new465 bytes
berdir’s picture

+++ b/config/schema/webform_mailchimp.schema.yml
@@ -21,7 +21,7 @@ webform.handler.mailchimp:
         label: 'Category'
         sequence:
-          type: string
+          type: integer
           label: 'Interest group ID'

I suspect what we are currently storing there is just the default result of #type checkboxes?

The recommended approach is that you run that through array_values(array_filter(), so you get this as result:

- group1
- group2

Then you don't need to check the value anymore at all, you can simply work with the list of values.

That would then definitely need an update function, however.

primsi’s picture

StatusFileSize
new1.22 KB

Followed the approach from above "mostly" :)

berdir’s picture

Title: Schema type for interest group id should be integer » Filter out not selected interest groups
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Updated issue summary and title. Looks good to me.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed with empty array init. :-)

Status: Fixed » Closed (fixed)

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