Problem/Motivation
Migrating a webform with submissions from d7 to d8, fields which had the multiple flag set weren't importing the expected values
Steps to reproduce
Create a webform in d7 with a select dropdown of set values that allows multiple selections, with another field, such as a text box before it in the webform
create some submissions for this webform
import the webform and webform submissions
the data from the select dropdown will either be absent in its entirety, or the data will be incorrect,
data where present will only include a single value for the select field, even if multiple values were selected.
this is due to two issues.
1. the $item variable not being cleared before it is repopulated, and because of the behaviour of php where a string is accessed with an array offset, eg if $item is not cleared before new data is assigned, and the data is a multiple value then the code will insert the new value into the string at the array offset used.
eg previous field held the value 'test', the select box has the options 1|one, 2|two and 3|three, with items 1 and 3 selected. after the select field data has been processed the value of $item will be '1e3t' rather than the expected ['0' => 1, '1' => 3];
2. where the value is multiple, on adding the data to the $submitted_data array the value is assigned using $submitted_data[$wf_submission['form_key']] = $item, overwriting the previous value for that key, if any, rather than using $submitted_data[$wf_submission['form_key']][] = $item to append the value.
Proposed resolution
Clear the $item variable inside the foreach loop, so that it is clear of data for each iteration of the loop
check if $item is an array before assigning it to the $submitted_data array and take the appropriate assignment action.
Remaining tasks
none
User interface changes
N/A
API changes
N/A
Data model changes
N/A