Importing data.csv
using Bob Olde Hampsink's Import plugin. Given that data.csv
has a 'table' item string thusly:
"Alcohol and Drug Treatment:RX-8450.3300,Counseling:RP-1400.8000-145,Mental Health Services:RR-5150.1500,Support Groups:PNPH-8100.4500-050"
(two columns, four rows. dead simple)
Lindsay tells us here that:
a table field contains a simple JSON string
So we are writing a plugin using Import's modifyImportRow hook and here's what we have in the hook loop:
...
// Arrange your content in a way that makes sense for your plugin
foreach ($fields as $handle => $value) {
if ($handle=="myTableHandle"){
$rows = explode(',', $value);
$tabledata = array();
foreach ($rows as $row) {
$rowarray = explode(':',$row);
$rowdata['col1'] = $rowarray[0];
$rowdata['col2'] = $rowarray[1];
$tabledata[] = $rowdata;
}
$value = json_encode($tabledata);
}
$content[$handle] = $value;
}
...
The import works, but the table field data (myTableHandle) remains NULL.
What else can we do to that string of table data to get the Import plugin to accept?