Skip to content

Commit

Permalink
Less intrusive doSave() overwrite of GridFieldDetailForm
Browse files Browse the repository at this point in the history
Fixes issues with valiation errors not showing due
to lack of PjaxResponseNegotiator support (parent implementation has changed).
  • Loading branch information
chillu committed Jul 10, 2013
1 parent 0e9c334 commit 6a9003e
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions code/forms/GridFieldSubsiteDetailForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,13 @@ function ItemEditForm() {

function doSave($data, $form) {
$new_record = $this->record->ID == 0;

if($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) {
$template = Subsite::get()->byID(intval($data['TemplateID']));
if($template) {
$this->record = $template->duplicate();
}
}

try {
$form->saveInto($this->record);
$this->record->write();
$this->gridField->getList()->add($this->record);
} catch(ValidationException $e) {
$form->sessionMessage($e->getResult()->message(), 'bad');
return Controller::curr()->redirectBack();
}

// TODO Save this item into the given relationship

$message = sprintf(
_t('GridFieldDetailForm.Saved', 'Saved %s %s'),
$this->record->singular_name(),
'<a href="' . $this->Link('edit') . '">"' . htmlspecialchars($this->record->Title, ENT_QUOTES) . '"</a>'
);

$form->sessionMessage($message, 'good');

return Controller::curr()->redirect($this->Link());
return parent::doSave($data, $form);
}
}

0 comments on commit 6a9003e

Please sign in to comment.