diff --git a/core/control/Controller.php b/core/control/Controller.php index 42a220608..db459dbb2 100644 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -147,20 +147,10 @@ class Controller extends ViewableData { Form::set_current_action($funcName); } - // Get the appropraite ocntroller: sometimes we want to get a form from another controller - if(isset($this->requestParams['formController'])) { - $formController = Director::getControllerForURL($this->requestParams['formController']); - - while(is_a($formController, 'NestedController')) { - $formController = $formController->getNestedController(); - } - - } else { - $formController = $this; - } - + $formOwner = $this->getFormOwner(); + // Create the form object - $form = $formController; + $form = $formOwner; $formObjParts = explode('.', $this->requestParams['executeForm']); foreach($formObjParts as $formMethod){ @@ -204,7 +194,7 @@ class Controller extends ViewableData { } }else{ - user_error("No form (" . Session::get('CMSMain.currentPage') . ") returned by $formController->class->$_REQUEST[executeForm]", E_USER_WARNING); + user_error("No form (" . Session::get('CMSMain.currentPage') . ") returned by $formOwner->class->$_REQUEST[executeForm]", E_USER_WARNING); } if(isset($_GET['debug_profile'])) Profiler::unmark("Controller", "populate form"); @@ -236,6 +226,9 @@ class Controller extends ViewableData { if(isset($_GET['debug_profile'])) Profiler::mark("$this->class::$funcName (controller action)"); $result = $this->$funcName($this->requestParams, $form); if(isset($_GET['debug_profile'])) Profiler::unmark("$this->class::$funcName (controller action)"); + + } else if(isset($formOwner) && $formOwner->hasMethod($funcName)) { + $result = $formOwner->$funcName($this->requestParams, $form); // Otherwise, try a handler method on the form object } else { @@ -290,6 +283,25 @@ class Controller extends ViewableData { $this->popCurrent(); return $this->response; } + + /** + * Return the object that is going to own a form that's being processed, and handle its execution. + * Note that the result needn't be an actual controller object. + */ + function getFormOwner() { + // Get the appropraite ocntroller: sometimes we want to get a form from another controller + if(isset($this->requestParams['formController'])) { + $formController = Director::getControllerForURL($this->requestParams['formController']); + + while(is_a($formController, 'NestedController')) { + $formController = $formController->getNestedController(); + } + return $formController; + + } else { + return $this; + } + } /** * This is the default action handler used if a method doesn't exist. diff --git a/widgets/Widget.php b/widgets/Widget.php index 80568d9c1..bc52b751e 100644 --- a/widgets/Widget.php +++ b/widgets/Widget.php @@ -94,7 +94,14 @@ class Widget extends DataObject { $this->Name = $this->class.$this->ID; $this->write(); } - + + function FormObjectLink($formName) { + if(is_numeric($this->ID)) { + return "WidgetFormProxy/index/$this->ID?executeForm=$formName"; + } else { + user_error("Attempted to create a form on a widget that hasn't been saved to the database.", E_USER_WARNING); + } + } } ?> \ No newline at end of file diff --git a/widgets/WidgetFormProxy.php b/widgets/WidgetFormProxy.php new file mode 100644 index 000000000..69a3a7ce4 --- /dev/null +++ b/widgets/WidgetFormProxy.php @@ -0,0 +1,12 @@ +urlParams['ID']); + + // Put this in once widget->canView is implemented + //if($widget->canView()) + return $widget; + + } +} \ No newline at end of file