Steps to reproduce

  1. Set up a list in CM and add a custom field containing multiple options (eg. foo, bar, foobar).
  2. Edit the list from the module UI /admin/config/services/campaignmonitor/lists
  3. Make sure the custom field is shown.
  4. Add the relevant list block to a region
  5. Subscribe to the list, checking all options

Expected behavior

All checked options from the custom field should remain checked after the form/block is submitted.

Actual behavior

Only the last checkbox selected when the form was submitted remains checked.

Resolution

This issue appears to be caused from a defect in the getSubscriber method of campaignmonitor.class.inc.
Specifically this code:

foreach ($result->response as $key => $value) {
  if ($key == 'CustomFields') {
    // Convert the custom fields object into a keyed array.
    $this->subscribers[$listId . $email][$key] = array();
    foreach ($value as $field) {
      $this->subscribers[$listId . $email][$key][$field->Key] = $field->Value;
    }
  }
  else {
    $this->subscribers[$listId . $email][$key] = $value;
  }
}

Changing the block above to the following seems to fix the problem:

foreach ($result->response as $key => $value) {
  if ($key == 'CustomFields') {
    // Convert the custom fields object into a keyed array.
    $this->subscribers[$listId . $email][$key] = array();
    foreach ($value as $field) {
      // Check if the field has been set. If not, set the value.
      if(!isset($this->subscribers[$listId . $email][$key][$field->Key])){
	$this->subscribers[$listId . $email][$key][$field->Key] = $field->Value;
      } 
      // If the field HAS been set, and there are additional values, check if the field is NOT an array?
      else if(! is_array($this->subscribers[$listId . $email][$key][$field->Key]) ) {
	// If the field is not an array, assign an array to the field, containing the previous value of the field and this new value.
        $this->subscribers[$listId . $email][$key][$field->Key] = array($this->subscribers[$listId . $email][$key][$field->Key], $field->Value);
      }
      // If the field is an array and there is an additional value, append it to the field rather than overwriting the field value.
      else {
	$this->subscribers[$listId . $email][$key][$field->Key][] = $field->Value;
      }
    }
  }
  else {
    $this->subscribers[$listId . $email][$key] = $value;
  }
}

Comments

cableman0408’s picture

Status: Active » Fixed

Thanks for the fix, it will be part of the next release :-)

Status: Fixed » Closed (fixed)

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