Add new form behavior override: formCreateModelObject

This commit is contained in:
Sam Georges 2014-06-16 18:00:14 +10:00
parent 8113371dac
commit 3ddddc03bb
1 changed files with 18 additions and 5 deletions

View File

@ -110,8 +110,10 @@ class FormController extends ControllerBehavior
try { try {
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create'); $this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create');
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('create[title]', 'backend::lang.form.create_title'); $this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang('create[title]', 'backend::lang.form.create_title');
$model = $this->createModel(); $model = $this->controller->formCreateModelObject();
$this->initForm($model); $this->initForm($model);
$this->controller->vars['formModel'] = $model;
} }
catch (Exception $ex) { catch (Exception $ex) {
$this->controller->handleError($ex); $this->controller->handleError($ex);
@ -124,7 +126,7 @@ class FormController extends ControllerBehavior
*/ */
public function create_onSave() public function create_onSave()
{ {
$model = $this->createModel(); $model = $this->controller->formCreateModelObject();
$this->initForm($model); $this->initForm($model);
$this->controller->formBeforeSave($model); $this->controller->formBeforeSave($model);
@ -452,8 +454,9 @@ class FormController extends ControllerBehavior
*/ */
public function formAfterDelete($model) {} public function formAfterDelete($model) {}
/** /**
* Finds a Model record based on it's primary identifier. This logic * Finds a Model record by its primary identifier, used by update actions. This logic
* can be changed by overriding it in the controller. * can be changed by overriding it in the controller.
* @param string $recordId * @param string $recordId
* @return Model * @return Model
@ -482,6 +485,16 @@ class FormController extends ControllerBehavior
return $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.
* @return Model
*/
public function formCreateModelObject()
{
return $this->createModel();
}
/** /**
* Called before the form fields are defined. * Called before the form fields are defined.
* @param Backend\Widgets\Form $host The hosting form widget * @param Backend\Widgets\Form $host The hosting form widget
@ -497,8 +510,8 @@ class FormController extends ControllerBehavior
public function formExtendFields($host) {} public function formExtendFields($host) {}
/** /**
* Extend supplied model, the model can be altered by overriding * Extend supplied model used by create and update actions, the model can
* it in the controller. * be altered by overriding it in the controller.
* @param Model $model * @param Model $model
* @return Model * @return Model
*/ */