Im getting an expecting string given array error on a variable in my fieldtype. When output / dumped to the template it is a string. This only happens when used within matrix field.
The trim function here is the specific line throwing the error:
$settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
getInputHtml() & prepValue()
public function prepValue($value)
{
$colour = new FruitStyle_PaletteModel();
if(is_array($value))
{
$colour->hex = $value['hex'];
$colour->opacity = $value['opacity'];
}
return $colour;
}
public function getInputHtml($name, $value)
{
craft()->templates->includeJsResource('fruitstyle/js/FruitPalette.js');
craft()->templates->includeCssResource('fruitstyle/css/palette.css');
craft()->templates->includeCssResource('fruitstyle/fonts/fruiticons/style.css');
$id = craft()->templates->formatInputId($name);
craft()->templates->includeJs('new FruitPalette("'.craft()->templates->namespaceInputId($id).'");');
// String or JSON
$settings = $this->getSettings();
if(filter_var($settings['colours'], FILTER_VALIDATE_URL))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $settings['colours']);
$colours = curl_exec($ch);
curl_close($ch);
$settings['colours'] = JsonHelper::decode($colours, true);
}
else
{
$settings['colours'] = explode(',', str_replace(' ', '', trim($settings['colours'])));
}
return craft()->templates->render('fruitstyle/_fieldtype/palette/input', array(
'id' => $id,
'name' => $name,
'value' => $value,
'settings' => $settings,
'specialOptions' => $this->_getSpecialOptions(),
));
}