Skip to content

Commit

Permalink
Added layout handover through submit process
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Feb 20, 2023
1 parent eeefab6 commit e938be8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/AbstractForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand All @@ -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);
};
Expand Down

0 comments on commit e938be8

Please sign in to comment.