From 4870a9f3402adb9c03d8fd8a25bc326284e25148 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Tue, 26 Aug 2008 00:25:22 +0000 Subject: [PATCH] API CHANGE: Allow definition of DataObject::getCMSAddFormFields() to alter modeladmin step 1 BUGFIX: Allow use of CheckboxSetField and other many-many editors in the add form of ModelAdmin BUGFIX: Fix direct access of (class)/(id)/edit on the ModelAdmiN git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@61505 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 00377fa0..f8330adb 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -547,7 +547,11 @@ class ModelAdmin_CollectionController extends Controller { */ public function AddForm() { $newRecord = new $this->modelClass(); - $fields = $newRecord->getCMSFields(); + if($newRecord->hasMethod('getCMSAddFormFields')) { + $fields = $newRecord->getCMSAddFormFields(); + } else { + $fields = $newRecord->getCMSFields(); + } $validator = ($newRecord->hasMethod('getCMSValidator')) ? $newRecord->getCMSValidator() : null; @@ -561,6 +565,8 @@ class ModelAdmin_CollectionController extends Controller { function doCreate($data, $form, $request) { $className = $this->getModelClass(); $model = new $className(); + // We write before saveInto, since this will let us save has-many and many-many relationships :-) + $model->write(); $form->saveInto($model); $model->write(); @@ -604,9 +610,13 @@ class ModelAdmin_RecordController extends Controller { if(Director::is_ajax()) { return $this->EditForm()->forAjaxTemplate(); } else { - return $this->parentController->parentController->customise(array( - 'EditForm' => $this->EditForm() - ))->renderWith('LeftAndMain'); + // This is really quite ugly; to fix will require a change in the way that customise() works. :-( + return$this->parentController->parentController->customise(array( + 'Right' => $this->parentController->parentController->customise(array( + 'EditForm' => $this->EditForm() + ))->renderWith('ModelAdmin_right') + ))->renderWith(array('ModelAdmin','LeftAndMain')); + return ; } } else { return "I can't find that item";