Closed petebacondarwin closed 11 years ago
Just checked and this is basically exactly how SiteTrees are published, although they manage to make it slightly more convoluted: In CMSMain there is a publish function that handles publish actions:
function publish($data, $form) {
$data['publish'] = '1';
return $this->save($data, $form);
}
This calls the save function but sets a publish flag. Inside the save function, this flag is checked:
// save form data into record
$form->saveInto($record);
$record->write();
// If the 'Save & Publish' button was clicked, also publish the page
if (isset($data['publish']) && $data['publish'] == 1) {
$record->doPublish();
There is a small bug in this solution, which is that the doSave function doesn't seem to then allow the publish response to be shown.
The
VersionedGridFieldDetailForm_ItemRequest#publish
method was only calling$record->doPublish
but not updating the record with the new data. This makes it call$this->doSave
first; this may be overkill and a bit ofmight be enough?
Also, changes the name of the
VersionedGridFieldDetailForm_ItemRequest#publish
method toVersionedGridFieldDetailForm_ItemRequest#doPublish
, in keeping with the convention ofdoSave
inGridFieldDetailForm_ItemRequest
Fixes Issue #19