From cd055ad437d48d0b50dd5c7992342dc5b88dced3 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 10 Feb 2016 19:38:35 +1100 Subject: [PATCH] Fixes formExtendModel method so it actually works. The extension must occur after the ::find() method, which will return a fresh object. When it occurs before, any changes to the model are lost. Where this may have prior been used to dynamically return a different model, the formCreateModelObject override method should return this value now. --- modules/backend/behaviors/FormController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index 48906da73..cbf79fa5a 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -180,6 +180,8 @@ class FormController extends ControllerBehavior ); $model = $this->controller->formCreateModelObject(); + $model = $this->controller->formExtendModel($model); + $this->initForm($model); } catch (Exception $ex) { @@ -364,8 +366,6 @@ class FormController extends ControllerBehavior { $class = $this->config->modelClass; $model = new $class(); - - $model = $this->controller->formExtendModel($model); return $model; } @@ -571,7 +571,6 @@ class FormController extends ControllerBehavior { } - /** * Finds a Model record by its primary identifier, used by update actions. This logic * can be changed by overriding it in the controller. @@ -584,7 +583,7 @@ class FormController extends ControllerBehavior throw new ApplicationException($this->getLang('not-found-message', 'backend::lang.form.missing_id')); } - $model = $this->createModel(); + $model = $this->controller->formCreateModelObject(); /* * Prepare query and find model record @@ -599,12 +598,14 @@ class FormController extends ControllerBehavior ])); } + $result = $this->controller->formExtendModel($result); + return $result; } /** - * Creates a new instance of a form model, used by create actions. This logic - * can be changed by overriding it in the controller. + * Creates a new instance of a form model. This logic can be changed + * by overriding it in the controller. * @return Model */ public function formCreateModelObject()