Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Make it possible to assign variables to view #1199

Open
wants to merge 5 commits into
base: typo3-v12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public function formAction(): ResponseInterface
$event = $this->eventDispatcher->dispatch(
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(
Expand Down
24 changes: 24 additions & 0 deletions Classes/Events/FormControllerFormActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ final class FormControllerFormActionEvent
*/
protected FormController $formController;

/**
* @var array<string,mixed>
*/
protected array $viewVariables = [];

/**
* @param Form|null $form
* @param FormController $formController
Expand Down Expand Up @@ -53,4 +58,23 @@ public function getFormController(): FormController
{
return $this->formController;
}

/**
* @return array<string,mixed>
*/
public function getViewVariables(): array
{
return $this->viewVariables;
}

/**
* Add additional variables to the view
*
* @param array<string,mixed> $variables
* @return void
*/
public function addViewVariables(array $variables): void
{
$this->viewVariables = array_merge($this->viewVariables, $variables);
}
}