From 40a2c3bb7c18e77fc09e1f9239d3c07d484d15c9 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 26 May 2009 06:01:36 +0000 Subject: [PATCH] ENHANCEMENT Support for DataObject->validate() and ValidationException catching in ModelAdmin->doSave() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@77855 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 4a2f8c33..c7bf2ba3 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -921,7 +921,13 @@ class ModelAdmin_RecordController extends Controller { */ function doSave($data, $form, $request) { $form->saveInto($this->currentRecord); - $this->currentRecord->write(); + + try { + $this->currentRecord->write(); + } catch(ValidationException $e) { + $form->sessionMessage($e->getResult()->message(), 'bad'); + } + // Behaviour switched on ajax. if(Director::is_ajax()) {