Skip to content

Commit e36a69b

Browse files
authored
[FEATURE] Make it possible to assign variables to view (#1199)
In event FormControllerFormActionEvent, make it possible to assign variables to view. Related: #1198
1 parent 3731fc4 commit e36a69b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Classes/Controller/FormController.php

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public function formAction(): ResponseInterface
8080
$event = $this->eventDispatcher->dispatch(
8181
GeneralUtility::makeInstance(FormControllerFormActionEvent::class, $form, $this)
8282
);
83+
if ($event->getViewVariables()) {
84+
$this->view->assignMultiple($event->getViewVariables());
85+
}
8386
$form = $event->getForm();
8487
SessionUtility::saveFormStartInSession($this->settings, $form);
8588
$this->view->assignMultiple(

Classes/Events/FormControllerFormActionEvent.php

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ final class FormControllerFormActionEvent
1818
*/
1919
protected FormController $formController;
2020

21+
/**
22+
* @var array<string,mixed>
23+
*/
24+
protected array $viewVariables = [];
25+
2126
/**
2227
* @param Form|null $form
2328
* @param FormController $formController
@@ -53,4 +58,23 @@ public function getFormController(): FormController
5358
{
5459
return $this->formController;
5560
}
61+
62+
/**
63+
* @return array<string,mixed>
64+
*/
65+
public function getViewVariables(): array
66+
{
67+
return $this->viewVariables;
68+
}
69+
70+
/**
71+
* Add additional variables to the view
72+
*
73+
* @param array<string,mixed> $variables
74+
* @return void
75+
*/
76+
public function addViewVariables(array $variables): void
77+
{
78+
$this->viewVariables = array_merge($this->viewVariables, $variables);
79+
}
5680
}

0 commit comments

Comments
 (0)