Skip to content

Commit

Permalink
Change functions in event
Browse files Browse the repository at this point in the history
  • Loading branch information
sypets committed Dec 11, 2024
1 parent 2f85e33 commit 3721341
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
5 changes: 4 additions & 1 deletion Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
33 changes: 12 additions & 21 deletions Classes/Events/FormControllerFormActionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use In2code\Powermail\Controller\FormController;
use In2code\Powermail\Domain\Model\Form;
use TYPO3Fluid\Fluid\View\ViewInterface;

final class FormControllerFormActionEvent
{
Expand All @@ -19,17 +18,19 @@ final class FormControllerFormActionEvent
*/
protected FormController $formController;

protected ViewInterface $view;
/**
* @var array<string,mixed>
*/
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;
}

/**
Expand Down Expand Up @@ -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

Check failure on line 62 in Classes/Events/FormControllerFormActionEvent.php

View workflow job for this annotation

GitHub Actions / PHPstan

Method In2code\Powermail\Events\FormControllerFormActionEvent::getViewVariables() return type has no value type specified in iterable type 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<string,mixed> $values array in the format array(key1 => value1, key2 => value2)
* @return ViewInterface an instance of $this, to enable chaining
* @param array<string,mixed> $additionalVariables
* @return void
*/
public function assignMultiple(array $values)
public function addViewVariables(array $variables): void

Check failure on line 73 in Classes/Events/FormControllerFormActionEvent.php

View workflow job for this annotation

GitHub Actions / PHPstan

Method In2code\Powermail\Events\FormControllerFormActionEvent::addViewVariables() has parameter $variables with no value type specified in iterable type array.

Check failure on line 73 in Classes/Events/FormControllerFormActionEvent.php

View workflow job for this annotation

GitHub Actions / PHPstan

PHPDoc tag @param references unknown parameter: $additionalVariables
{
$this->view->assignMultiple($values);
return $this->view;
$this->viewVariables = array_merge($this->viewVariables, $variables);
}
}

0 comments on commit 3721341

Please sign in to comment.