Too bad no one could help me, but found a solution in the meantime. Inspired by others on Github and Stackoverflow (https://craftcms.stackexchange.com/a/14158/3937). Maybe my solution helps someone else with the same problem.
I created a method in my controller which gathers all values from the fields and prepares an array of it, which has exactly the same format as the CP in the browser sends when saving a new draft. I use this array to feed the method setContentFromPost
on the EntryDraftModel
, together with the incoming POST
data from craft()->request->getParam('fields')
.
public function getFieldValuesFromEntry(BaseElementModel $entry, $fields = null)
{
foreach ($entry->fieldLayout->fields as $fieldLayoutField) {
$fieldHandle = $fieldLayoutField->field->handle;
if ($fields === null || in_array($fieldHandle, $fields)) {
$fieldValue = $entry->getFieldValue($fieldHandle);
if ($fieldValue instanceof RichTextData)
{
$value = $fieldValue->getRawContent();
}
elseif ($fieldValue instanceof ElementCriteriaModel)
{
$value = $fieldValue->ids();
}
elseif ($fieldValue instanceof SingleOptionFieldData)
{
$value = $fieldValue->value;
}
else
{
$value = $fieldValue;
}
$field[$fieldHandle] = $value;
}
}
return $field;
}
And this is the snippet where I feed it into the draft ($entryFields
is here the output of the method above):
$draftFields = craft()->request->getParam('fields');
$draft->setContentFromPost(array_merge($entryFields, $draftFields));
If anybody has a more efficient solution to fix my problem, please let me now. Cheers!