Fixes #373 - FormController can now accept different form fields for create,update,preview
This commit is contained in:
parent
48b90e86b6
commit
3e5d6452fb
|
|
@ -23,6 +23,21 @@ use Exception;
|
|||
*/
|
||||
class FormController extends ControllerBehavior
|
||||
{
|
||||
/**
|
||||
* @var string Default context for "create" pages.
|
||||
*/
|
||||
const CONTEXT_CREATE = 'create';
|
||||
|
||||
/**
|
||||
* @var string Default context for "update" pages.
|
||||
*/
|
||||
const CONTEXT_UPDATE = 'update';
|
||||
|
||||
/**
|
||||
* @var string Default context for "preview" pages.
|
||||
*/
|
||||
const CONTEXT_PREVIEW = 'preview';
|
||||
|
||||
/**
|
||||
* @var Backend\Classes\WidgetBase Reference to the widget object.
|
||||
*/
|
||||
|
|
@ -80,7 +95,22 @@ class FormController extends ControllerBehavior
|
|||
{
|
||||
$context = $this->formGetContext();
|
||||
|
||||
$config = $this->makeConfig($this->config->form);
|
||||
/*
|
||||
* Each page can supply a unique form definition, if desired
|
||||
*/
|
||||
$formFields = $this->config->form;
|
||||
|
||||
if ($context == self::CONTEXT_CREATE) {
|
||||
$formFields = $this->getConfig('create[form]', $formFields);
|
||||
}
|
||||
elseif ($context == self::CONTEXT_UPDATE) {
|
||||
$formFields = $this->getConfig('update[form]', $formFields);
|
||||
}
|
||||
elseif ($context == self::CONTEXT_PREVIEW) {
|
||||
$formFields = $this->getConfig('preview[form]', $formFields);
|
||||
}
|
||||
|
||||
$config = $this->makeConfig($formFields);
|
||||
$config->model = $model;
|
||||
$config->arrayName = class_basename($model);
|
||||
$config->context = $context;
|
||||
|
|
@ -140,7 +170,7 @@ class FormController extends ControllerBehavior
|
|||
public function create($context = null)
|
||||
{
|
||||
try {
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create');
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', self::CONTEXT_CREATE);
|
||||
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
|
||||
'create[title]',
|
||||
'backend::lang.form.create_title'
|
||||
|
|
@ -160,7 +190,7 @@ class FormController extends ControllerBehavior
|
|||
*/
|
||||
public function create_onSave($context = null)
|
||||
{
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', 'create');
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('create[context]', self::CONTEXT_CREATE);
|
||||
$model = $this->controller->formCreateModelObject();
|
||||
$this->initForm($model);
|
||||
|
||||
|
|
@ -195,7 +225,7 @@ class FormController extends ControllerBehavior
|
|||
public function update($recordId = null, $context = null)
|
||||
{
|
||||
try {
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', 'update');
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', self::CONTEXT_UPDATE);
|
||||
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
|
||||
'update[title]',
|
||||
'backend::lang.form.update_title'
|
||||
|
|
@ -216,7 +246,7 @@ class FormController extends ControllerBehavior
|
|||
*/
|
||||
public function update_onSave($recordId = null, $context = null)
|
||||
{
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', 'update');
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('update[context]', self::CONTEXT_UPDATE);
|
||||
$model = $this->controller->formFindModelObject($recordId);
|
||||
$this->initForm($model);
|
||||
|
||||
|
|
@ -245,7 +275,7 @@ class FormController extends ControllerBehavior
|
|||
*/
|
||||
public function update_onDelete($recordId = null)
|
||||
{
|
||||
$this->context = $this->getConfig('update[context]', 'update');
|
||||
$this->context = $this->getConfig('update[context]', self::CONTEXT_UPDATE);
|
||||
$model = $this->controller->formFindModelObject($recordId);
|
||||
$this->initForm($model);
|
||||
|
||||
|
|
@ -273,7 +303,7 @@ class FormController extends ControllerBehavior
|
|||
public function preview($recordId = null, $context = null)
|
||||
{
|
||||
try {
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('preview[context]', 'preview');
|
||||
$this->context = strlen($context) ? $context : $this->getConfig('preview[context]', self::CONTEXT_PREVIEW);
|
||||
$this->controller->pageTitle = $this->controller->pageTitle ?: $this->getLang(
|
||||
'preview[title]',
|
||||
'backend::lang.form.preview_title'
|
||||
|
|
|
|||
Loading…
Reference in New Issue