I would say you can do this yeah, it just take a little figuring out is all.
Your input template could look something like:
<input type="text" name="{{ name }}[title]" value="{{ value.title is defined ? value.title }}">
<input type="text" name="{{ name }}[description]" value="{{ value.description is defined ? value.description }}">
<input type="text" name="{{ name }}[caption]" value="{{ value.caption is defined ? value.caption }}">
<input type="text" name="{{ name }}[thumb]" value="{{ value.thumb is defined ? value.thumb }}">
Then in your fieldtypes main class, something like:
public function getInputHtml($name, $value)
{
// If value is null, we set it to an array to prevent template errors
if(!$value)
{
$value = array();
}
return craft()->templates->render('bosh/input', array(
'name' => $name,
'value' => $value
));
}
public function prepValueFromPost($value)
{
return json_encode($value);
}
public function prepValue($value)
{
return json_decode($value, TRUE);
}
So basically you are settings the fieldtype value to an array of pluginHandle[field]
which then you json_encode
so it can all go into database without any issues.
Then when you retrieve the value from the DB, its a string, so you json_decode
it into an array. The TRUE
part states you want an associative array, rather than a stdClass
object.
Thats pretty much it at a basic level :)