From efbdaf7b2efe24388a8243a30d30b8bfa3131ff5 Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Mon, 26 Jan 2009 21:09:26 +0000 Subject: [PATCH] Undoing change committed in r 70734 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@70738 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index 79ea1239..39cbcc29 100644 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -670,28 +670,32 @@ class ModelAdmin_CollectionController extends Controller { } /** - * Returns a form for editing the attached model + * Returns a form suitable for adding a new model, falling back on the default edit form + * + * @return Form */ public function AddForm() { $newRecord = new $this->modelClass(); + if($newRecord->canCreate()){ if($newRecord->hasMethod('getCMSAddFormFields')) { $fields = $newRecord->getCMSAddFormFields(); } else { $fields = $newRecord->getCMSFields(); } - + $validator = ($newRecord->hasMethod('getCMSValidator')) ? $newRecord->getCMSValidator() : null; - - $actions = new FieldSet( + + $actions = new FieldSet ( new FormAction("doCreate", _t('ModelAdmin.ADDBUTTON', "Add")) ); - + $form = new Form($this, "AddForm", $fields, $actions, $validator); - + $form->loadDataFrom($newRecord); + return $form; } - } + } function doCreate($data, $form, $request) { $className = $this->getModelClass();