Steps to reproduce
- Set up a list in CM and add a custom field containing multiple options (eg. foo, bar, foobar).
- Edit the list from the module UI /admin/config/services/campaignmonitor/lists
- Make sure the custom field is shown.
- Add the relevant list block to a region
- 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
Comment #1
cableman0408 commentedThanks for the fix, it will be part of the next release :-)