From 52d067ead4334e6b1836569c6d496f8dc229bf2d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 13 Apr 2010 20:36:55 +0000 Subject: [PATCH] BUGFIX: removing hardcoded reference to ModelAdmin_RecordController, also added getters for model controllers. (from r97231) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@102714 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/ModelAdmin.php | 61 +++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/code/ModelAdmin.php b/code/ModelAdmin.php index ce9a9e88..8ea8ad52 100755 --- a/code/ModelAdmin.php +++ b/code/ModelAdmin.php @@ -166,6 +166,43 @@ abstract class ModelAdmin extends LeftAndMain { static function get_page_length(){ return self::$page_length; } + + /** + * Return the class name of the collection controller + * + * @param string $model model name to get the controller for + * @return string the collection controller class + */ + function getCollectionControllerClass($model) { + $models = $this->getManagedModels(); + + if(isset($models[$model]['collection_controller'])) { + $class = $models[$model]['collection_controller']; + } else { + $class = $this->stat('collection_controller_class'); + } + + return $class; + } + + /** + * Return the class name of the record controller + * + * @param string $model model name to get the controller for + * @return string the record controller class + */ + function getRecordControllerClass($model) { + $models = $this->getManagedModels(); + + if(isset($models[$model]['record_controller'])) { + $class = $models[$model]['record_controller']; + } else { + $class = $this->stat('record_controller_class'); + } + + return $class; + } + /** * Add mappings for generic form constructors to automatically delegate to a scaffolded form object. */ @@ -182,14 +219,7 @@ abstract class ModelAdmin extends LeftAndMain { * Base scaffolding method for returning a generic model instance. */ public function bindModelController($model, $request = null) { - $models = $this->getManagedModels(); - - if(isset($models[$model]['collection_controller'])) { - $class = $models[$model]['collection_controller']; - } else { - $class = $this->stat('collection_controller_class'); - } - + $class = $this->getCollectionControllerClass($model); return new $class($this, $model); } @@ -311,7 +341,7 @@ class ModelAdmin_CollectionController extends Controller { function getModelClass() { return $this->modelClass; } - + /** * Delegate to different control flow, depending on whether the * URL parameter is a number (record id) or string (action). @@ -335,15 +365,7 @@ class ModelAdmin_CollectionController extends Controller { * @return RecordController */ public function handleID($request) { - $models = $this->parentController->getManagedModels(); - $model = $this->getModelClass(); - - if(isset($models[$model]['record_controller'])) { - $class = $models[$model]['record_controller']; - } else { - $class = $this->parentController->stat('record_controller_class'); - } - + $class = $this->parentController->getRecordControllerClass($this->getModelClass()); return new $class($this, $request); } @@ -814,7 +836,8 @@ class ModelAdmin_CollectionController extends Controller { $model->write(); if(Director::is_ajax()) { - $recordController = new ModelAdmin_RecordController($this, $request, $model->ID); + $class = $this->parentController->getRecordControllerClass($this->getModelClass()); + $recordController = new $class($this, $request, $model->ID); return new SS_HTTPResponse( $recordController->EditForm()->formHtmlContent(), 200,