From e938be8900b7a1c0e7052ccd29f5c3324b70d763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Mon, 20 Feb 2023 16:15:57 +0100 Subject: [PATCH] Added layout handover through submit process --- src/AbstractForm.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/AbstractForm.php b/src/AbstractForm.php index 6f24917..5d11fdb 100644 --- a/src/AbstractForm.php +++ b/src/AbstractForm.php @@ -186,11 +186,14 @@ public function render(): void $template->setTranslator($this->translator); $this->onRender($this, $template); + $form = $this->getForm()->setDefaults([ + '__layout' => $this->layout->value, + ]); $templateFile = $template->getFile() ?? $this->getTemplateFile(); $template->render($templateFile, [ - 'form' => $this->getForm(), 'layout' => $this->layout, + 'form' => $form, ]); } @@ -199,9 +202,14 @@ protected function createComponentForm(): Form { $form = new $this->formClass; $form->setTranslator($this->translator); + $form->addHidden('__layout'); $form->addProtection(); $form->onValidate[] = function(Form $form, ArrayHash $data): void { + if ($layout = Layout::tryMake($data->__layout ?? '')) { + $this->setLayout($layout); + } + $this->handleValidate($form, $data); $this->onValidate($form, $data); };