From 37213410770cd54662fc31b1cee84bc3a4a72594 Mon Sep 17 00:00:00 2001 From: Sybille Peters Date: Wed, 11 Dec 2024 20:59:09 +0100 Subject: [PATCH] Change functions in event --- Classes/Controller/FormController.php | 5 ++- .../Events/FormControllerFormActionEvent.php | 33 +++++++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Classes/Controller/FormController.php b/Classes/Controller/FormController.php index c7ecd9aec..c40735cf7 100644 --- a/Classes/Controller/FormController.php +++ b/Classes/Controller/FormController.php @@ -78,8 +78,11 @@ public function formAction(): ResponseInterface /** @var FormControllerFormActionEvent $event */ $event = $this->eventDispatcher->dispatch( - GeneralUtility::makeInstance(FormControllerFormActionEvent::class, $form, $this, $this->view) + GeneralUtility::makeInstance(FormControllerFormActionEvent::class, $form, $this) ); + if ($event->getViewVariables()) { + $this->view->assignMultiple($event->getViewVariables()); + } $form = $event->getForm(); SessionUtility::saveFormStartInSession($this->settings, $form); $this->view->assignMultiple( diff --git a/Classes/Events/FormControllerFormActionEvent.php b/Classes/Events/FormControllerFormActionEvent.php index 7b873cc48..c25f8ef1c 100644 --- a/Classes/Events/FormControllerFormActionEvent.php +++ b/Classes/Events/FormControllerFormActionEvent.php @@ -5,7 +5,6 @@ use In2code\Powermail\Controller\FormController; use In2code\Powermail\Domain\Model\Form; -use TYPO3Fluid\Fluid\View\ViewInterface; final class FormControllerFormActionEvent { @@ -19,17 +18,19 @@ final class FormControllerFormActionEvent */ protected FormController $formController; - protected ViewInterface $view; + /** + * @var array + */ + protected array $viewVariables = []; /** * @param Form|null $form * @param FormController $formController */ - public function __construct(?Form $form, FormController $formController, ViewInterface $view) + public function __construct(?Form $form, FormController $formController) { $this->form = $form; $this->formController = $formController; - $this->view = $view; } /** @@ -58,29 +59,19 @@ public function getFormController(): FormController return $this->formController; } - /** - * Add a variable to the view data collection. - * Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible - * - * @param string $key Key of variable - * @param mixed $value Value of object - * @return ViewInterface an instance of $this, to enable chaining - */ - public function assign(string $key, mixed $value) + public function getViewVariables(): array { - $this->view->assign($key, $value); - return $this->view; + return $this->viewVariables; } /** - * Add multiple variables to the view data collection + * Add additional variables to the view * - * @param array $values array in the format array(key1 => value1, key2 => value2) - * @return ViewInterface an instance of $this, to enable chaining + * @param array $additionalVariables + * @return void */ - public function assignMultiple(array $values) + public function addViewVariables(array $variables): void { - $this->view->assignMultiple($values); - return $this->view; + $this->viewVariables = array_merge($this->viewVariables, $variables); } }