arambalakjian / DataObject-as-Page

A SilverStripe module for displaying DataObjects as Pages
53 stars 27 forks source link

fix(VersionedGridFieldDetailForm): Save when publishing #20

Closed petebacondarwin closed 11 years ago

petebacondarwin commented 11 years ago

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 of

$form->saveInto($this->record);
$this->record->write();

might be enough?

Also, changes the name of the VersionedGridFieldDetailForm_ItemRequest#publish method to VersionedGridFieldDetailForm_ItemRequest#doPublish, in keeping with the convention of doSave in GridFieldDetailForm_ItemRequest

Fixes Issue #19

petebacondarwin commented 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();
petebacondarwin commented 11 years ago

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.