-
Notifications
You must be signed in to change notification settings - Fork 29
Description
I've been pulling my hair out for an entire day as to why I can't import multiple values into a Select Box Link via the XML Importer.
I remember having the discussion with @brendo on the forum (http://www.getsymphony.com/discuss/thread/45612/) as to how to do it, and yet it still just wouldn't work. Single values always worked, but never multiple values.
Take this
<items>
<item>42</item>
<item>handle</item>
<item>String</item>
</items>Using an expression of ./items/item should allow a developer to add these values to a multiple Select Box Link, yet it fails every time. It always concatenates the values into a string.
I never even thought that it was the SBL itself that was doing the dirty here, as it's not changed with this regard for sooo long, but I was wrong.
No matter what you pass the SBL's prepareImportValue function, using the getValue style, it always returns a flat string, even though the field itself is more than capable of ingesting an array.
I've hacked a change to it as follows.
public function prepareImportValue($data, $mode, $entry_id = null)
{
$message = $status = null;
$modes = (object) $this->getImportModes();
if (!is_array($data)) {
$data = array($data);
}
if ($mode === $modes->getValue) {
if ($this->get('allow_multiple_selection') === 'no') {
return implode('', $data);
}
return $data; // <-- I have changed this little line
} elseif ($mode === $modes->getPostdata) {
// Iterate over $data, and where the value is not an ID,
// do a lookup for it!
foreach ($data as $key => &$value) {
if (!is_numeric($value) && !is_null($value)) {
$value = $this->fetchIDfromValue($value);
}
}
return $this->processRawFieldData($data, $status, $message, true, $entry_id);
}
return null;
}Instead of (as it currently is) implode($data) being where I have changed it (as commented), I let it return an array!
Now the XML Importer finally works as expected. That's three years of me having to find hacks and convoluted methods of associating import data. One line.
@brendo can you clarify this change and let me know if it will break anything else? @nitriques could you test it too for me before I PR this change, I want to make sure that I don't break anything.
Also, this will need replicating into the Association Field if all is good.