Andrea Malalana
Hey there, we talked about this before, but as I've been needing to "fix" this issue in my code in multiple places, I figured I'd post it here to see if you find a more permanent solution.
Basically, with the latest version of Articles Field, where you introduced the ajax loading for faster loading only when the input is in view, an issue araised:
- Have an Articles Field inside a Subform
- Make sure it can have multiple values
- Select multiple values in it and save
- If you save while it's in view, all it's fine, it gets saved in the db json correctly as array with multiple elements:
["15299","15416"]
- If you save it while it's NOT in view, it gets saved in the db json wrong, as a single array element and comma separated string:
["15299,15416"]
While this doesn't cause issues with the default field output - which uses the ->value, this causes issue when trying to use the ->rawvalue in custom code - as the rawvalue is not an array as it should be, in the second broken case.
In my code I keep fixing it with a function like this:
// Fix faulty syntax that may get saved if the field is not in view
self::fixArticlesFieldRawValue($subform_row['wrestler']->rawvalue);
public static function fixArticlesFieldRawValue(&$rawvalue)
{
if ( ! is_array($rawvalue))
{
return $rawvalue;
}
// If the first element of the array contains a comma, split it
if (strpos($rawvalue[0], ',') !== false)
{
$rawvalue = explode(',', $rawvalue[0]);
}
return $rawvalue;
}
But as it's starting to become lots and lots of places where I need to apply this, it would be great if you could fix it on the extension itself (either by saving the rawvalue correctly in the json, or by manipulating the object that gets generated from the json)