public function getDecodedValue($name)
{
$value = null;
if (isset($this->values[$name])) {
$fieldtype = $this->fieldtype($name);
$fieldinfo = $this->fieldinfo($name);
$allowtwig = !empty($fieldinfo['allowtwig']);
switch ($fieldtype) {
case 'markdown':
// Deprecated: This should be moved to a render function in
// Bolt\Storage\Field\Type\MarkdownType eventually.
$value = $this->app['markdown']->text($this->values[$name]);
$value = $this->preParse($value, $allowtwig);
$value = new \Twig_Markup($value, 'UTF-8');
break;
case 'html':
case 'text':
case 'textarea':
$value = $this->preParse($this->values[$name], $allowtwig);
$value = new \Twig_Markup($value, 'UTF-8');
break;
case 'imagelist':
case 'filelist':
if (is_string($this->values[$name])) {
// Parse the field as JSON, return the array
$value = json_decode($this->values[$name]);
} else {
// Already an array, do nothing.
$value = $this->values[$name];
}
break;
case 'image':
if (is_array($this->values[$name]) && isset($this->values[$name]['file'])) {
$value = $this->values[$name]['file'];
} else {
$value = $this->values[$name];
}
break;
default:
$value = $this->values[$name];
break;
}
}
return $value;
}