diff --git a/modules/backend/behaviors/FormController.php b/modules/backend/behaviors/FormController.php index ae58bb475f..1b6c125296 100644 --- a/modules/backend/behaviors/FormController.php +++ b/modules/backend/behaviors/FormController.php @@ -191,7 +191,9 @@ public function initForm($model, $context = null) protected function prepareVars($model) { $this->controller->vars['formModel'] = $model; + $this->controller->vars['formConfig'] = $this->getConfig(); $this->controller->vars['formContext'] = $this->formGetContext(); + $this->controller->vars['formController'] = $this; $this->controller->vars['formRecordName'] = Lang::get($this->getConfig('name', 'backend::lang.model.name')); } @@ -473,6 +475,10 @@ public function makeRedirect($context = null, $model = null) return Redirect::refresh(); } + if (post('new', false)) { + return Redirect::to($this->controller->actionUrl('create')); + } + if (post('redirect', true)) { $redirectUrl = $this->controller->formGetRedirectUrl($context, $model); } @@ -882,4 +888,20 @@ public static function extendFormFields($callback) call_user_func_array($callback, [$widget, $widget->model, $widget->getContext()]); }); } + + /** + * Controller accessor for making partials within this behavior. + */ + public function formMakePartial(string $partial, array $params = []): string + { + $contents = $this->controller->makePartial('form_' . $this->context . '_' . $partial, $params + $this->vars, false); + if (!$contents) { + $contents = $this->controller->makePartial('form_' . $partial, $params + $this->vars, false); + } + if (!$contents) { + $contents = $this->makePartial($partial, $params); + } + + return $contents; + } } diff --git a/modules/backend/behaviors/formcontroller/partials/_toolbar.php b/modules/backend/behaviors/formcontroller/partials/_toolbar.php new file mode 100644 index 0000000000..d4929319fb --- /dev/null +++ b/modules/backend/behaviors/formcontroller/partials/_toolbar.php @@ -0,0 +1,81 @@ +name ?? ''; +?> + +
+ + + + + + +
+ +
+ + + + + + +
+ diff --git a/modules/backend/behaviors/formcontroller/views/create.php b/modules/backend/behaviors/formcontroller/views/create.php index 308d711d6b..12080a6fc8 100644 --- a/modules/backend/behaviors/formcontroller/views/create.php +++ b/modules/backend/behaviors/formcontroller/views/create.php @@ -1,9 +1,5 @@ getClassExtension(\Backend\Behaviors\FormController::class); -$formConfig = $formController->getConfig(); - // Decide which layout we should be rendering $layout = $this->formLayout ?? $formConfig->formLayout ?? null; if (!in_array($layout, ['standard', 'sidebar', 'fancy'])) { @@ -21,7 +17,4 @@ $this->appendViewPath(sprintf('%s/create/%s', __DIR__, $layout)); // Render the form layout -echo $this->makePartial(sprintf('create/%s.php', $layout), [ - 'formController' => $formController, - 'formConfig' => $formConfig, -]); +echo $this->makePartial(sprintf('create/%s.php', $layout)); diff --git a/modules/backend/behaviors/formcontroller/views/create/_sidebar.php b/modules/backend/behaviors/formcontroller/views/create/_sidebar.php index 2e65cdf8bb..f278789de0 100644 --- a/modules/backend/behaviors/formcontroller/views/create/_sidebar.php +++ b/modules/backend/behaviors/formcontroller/views/create/_sidebar.php @@ -11,32 +11,7 @@
-
- - - - - -
+ formMakePartial('toolbar') ?>
diff --git a/modules/backend/behaviors/formcontroller/views/create/_standard.php b/modules/backend/behaviors/formcontroller/views/create/_standard.php index 45a39802f7..7b88ff8b33 100644 --- a/modules/backend/behaviors/formcontroller/views/create/_standard.php +++ b/modules/backend/behaviors/formcontroller/views/create/_standard.php @@ -13,32 +13,7 @@
-
- - - - - -
+ formMakePartial('toolbar') ?>
diff --git a/modules/backend/behaviors/formcontroller/views/preview.php b/modules/backend/behaviors/formcontroller/views/preview.php index 29d64847e4..1429909ce1 100644 --- a/modules/backend/behaviors/formcontroller/views/preview.php +++ b/modules/backend/behaviors/formcontroller/views/preview.php @@ -1,8 +1,5 @@ getClassExtension(\Backend\Behaviors\FormController::class); -$formConfig = $formController->getConfig(); // Decide which layout we should be rendering $layout = $this->formLayout ?? $formConfig->formLayout ?? null; @@ -21,7 +18,4 @@ $this->appendViewPath(sprintf('%s/preview/%s', __DIR__, $layout)); // Render the form layout -echo $this->makePartial(sprintf('preview/%s.php', $layout), [ - 'formController' => $formController, - 'formConfig' => $formConfig, -]); +echo $this->makePartial(sprintf('preview/%s.php', $layout)); diff --git a/modules/backend/behaviors/formcontroller/views/update.php b/modules/backend/behaviors/formcontroller/views/update.php index fe9fe58210..eb439c1f9a 100644 --- a/modules/backend/behaviors/formcontroller/views/update.php +++ b/modules/backend/behaviors/formcontroller/views/update.php @@ -1,9 +1,5 @@ getClassExtension(\Backend\Behaviors\FormController::class); -$formConfig = $formController->getConfig(); - // Decide which layout we should be rendering $layout = $this->formLayout ?? $formConfig->formLayout ?? null; if (!in_array($layout, ['standard', 'sidebar', 'fancy'])) { @@ -21,7 +17,4 @@ $this->appendViewPath(sprintf('%s/update/%s', __DIR__, $layout)); // Render the form layout -echo $this->makePartial(sprintf('update/%s.php', $layout), [ - 'formController' => $formController, - 'formConfig' => $formConfig, -]); +echo $this->makePartial(sprintf('update/%s.php', $layout)); diff --git a/modules/backend/behaviors/formcontroller/views/update/_sidebar.php b/modules/backend/behaviors/formcontroller/views/update/_sidebar.php index 75ac048f69..f278789de0 100644 --- a/modules/backend/behaviors/formcontroller/views/update/_sidebar.php +++ b/modules/backend/behaviors/formcontroller/views/update/_sidebar.php @@ -11,45 +11,7 @@
-
- - - - - - - -
+ formMakePartial('toolbar') ?>
diff --git a/modules/backend/behaviors/formcontroller/views/update/_standard.php b/modules/backend/behaviors/formcontroller/views/update/_standard.php index b9327585a2..7b88ff8b33 100644 --- a/modules/backend/behaviors/formcontroller/views/update/_standard.php +++ b/modules/backend/behaviors/formcontroller/views/update/_standard.php @@ -13,43 +13,7 @@
-
- - - - - - -
+ formMakePartial('toolbar') ?>
diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 92888d965d..2645960d33 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -265,6 +265,7 @@ 'not_found' => 'Form record with an ID of :id could not be found.', 'action_confirm' => 'Are you sure?', 'create' => 'Create', + 'create_and_new' => 'Create and new', 'create_and_close' => 'Create and close', 'creating' => 'Creating...', 'creating_name' => 'Creating :name...', diff --git a/modules/backend/lang/es/lang.php b/modules/backend/lang/es/lang.php index c10026cf7f..9a06c3719a 100644 --- a/modules/backend/lang/es/lang.php +++ b/modules/backend/lang/es/lang.php @@ -195,6 +195,7 @@ 'not_found' => 'El registro del formulario con un ID de :id no se pudo encontrar.', 'action_confirm' => '¿Está usted seguro?', 'create' => 'Crear', + 'create_and_new' => 'Crear y nuevo', 'create_and_close' => 'Crear y cerrar', 'creating' => 'Creando...', 'creating_name' => 'Creando :name...', diff --git a/modules/backend/lang/fr/lang.php b/modules/backend/lang/fr/lang.php index 251d800c18..ef499132bf 100644 --- a/modules/backend/lang/fr/lang.php +++ b/modules/backend/lang/fr/lang.php @@ -263,6 +263,7 @@ 'not_found' => 'Aucun enregistrement de formulaire ne correspond à l\'ID :id.', 'action_confirm' => 'Confirmer l\'action ?', 'create' => 'Créer', + 'create_and_new' => 'Créer et nouveau', 'create_and_close' => 'Créer et fermer', 'creating' => 'Création en cours…', 'creating_name' => 'Création d\'un(e) :name en cours…', diff --git a/modules/backend/lang/nl/lang.php b/modules/backend/lang/nl/lang.php index 425a3f4c10..52495bb734 100644 --- a/modules/backend/lang/nl/lang.php +++ b/modules/backend/lang/nl/lang.php @@ -259,6 +259,7 @@ 'not_found' => 'Het formulier met record ID :id is niet gevonden.', 'action_confirm' => 'Weet je het zeker?', 'create' => 'Maken', + 'create_and_new' => 'Maken en nieuw', 'create_and_close' => 'Maken en sluiten', 'creating' => 'Maken...', 'creating_name' => ':name maken...', diff --git a/modules/backend/lang/pl/lang.php b/modules/backend/lang/pl/lang.php index 1e9a18a5d0..8d47307cd1 100644 --- a/modules/backend/lang/pl/lang.php +++ b/modules/backend/lang/pl/lang.php @@ -253,6 +253,7 @@ 'not_found' => 'Rekord formularza o ID :id nie został znaleziony.', 'action_confirm' => 'Czy jesteś pewny?', 'create' => 'Stwórz', + 'create_and_new' => 'Utwórz i nowe', 'create_and_close' => 'Stwórz i zamknij', 'creating' => 'Tworzenie...', 'creating_name' => 'Tworzenie :name...', diff --git a/modules/backend/lang/ru/lang.php b/modules/backend/lang/ru/lang.php index 828f5e1b52..ec071a9590 100644 --- a/modules/backend/lang/ru/lang.php +++ b/modules/backend/lang/ru/lang.php @@ -264,6 +264,7 @@ 'not_found' => 'Форма записи с идентификатором :ID не найдена.', 'action_confirm' => 'Вы уверены, что хотите сделать это?', 'create' => 'Создать', + 'create_and_new' => 'Создать и новый', 'create_and_close' => 'Создать и закрыть', 'creating' => 'Создание...', 'creating_name' => 'Создание :name...',