powermail icon indicating copy to clipboard operation
powermail copied to clipboard

No access to view in *RenderViewEvents

Open haraldwitt opened this issue 1 year ago • 1 comments
trafficstars

Powermail dispatches 3 events before rendering a view. These are:

  • FormControllerCreateActionBeforeRenderViewEvent
  • FormControllerDisclaimerActionBeforeRenderViewEvent
  • FormControllerOptinConfirmActionBeforeRenderViewEvent

But there is no possibility to influence the view, e. g. via

$view->assign('mySpecialError',`` $mySpecialError);

This is because the $formController itself is only available via a getter (no setter present). And the view is of course protected (inherited from TYPO3\CMS\Extbase\Mvc\Controller\ActionController --> AbstractController --> FormController).

Is it possible to include the view in the parameters of the constructor of the three events and to introduce getView() and setView($view)? Of course the view must be overtaken back in FormController after the event has finished. If desired I could create a pull request for that.

Alternatively it would be helpful to get the $formController per reference (&$formController) in the constructor of the events.

Or should there be an setter for the $formController in general for all Events?

The last and most ugly possibility would be to manipulate the $mail object, where getter and setter are present and the object is overtaken back in FormController after the event has finished.

Update: This "last and ugly" will not function because in the "Powermail Confirm Failed Page" (Resources/Private/Templates/Form/OptinConfirm.html) only {settings} and {labelKey} are available, NO {mail} object. And the view is not accessible. That's just the problem.

Thx for ideas and comments Harald

haraldwitt avatar Jun 12 '24 05:06 haraldwitt

Now I've created a pull request: https://github.com/in2code-de/powermail/pull/1054

haraldwitt avatar Jun 12 '24 13:06 haraldwitt

There is a follow-up issue and PR for this. So I close this one.

mschwemer avatar Oct 04 '24 08:10 mschwemer

Where is the PR and the follow-up issue? I can't find it.

cweiske avatar Apr 15 '25 13:04 cweiske

Hi Christian,

as you can read here: https://github.com/in2code-de/powermail/pull/1054#issuecomment-2374415620 my PR was splitted into two PRs. One of them, regarding the VariablesViewHelper was overtaken meanwhile.

But the other one regarding the access to view in *RenderViewEvents gave a lot of failings tests and mschwemer rejected the PR. And because I'm not experienced in tests, I gave up and made a small patch for myself. Now I'm retired. But if you're interested in the patch: I add it here. It's currently running with Typo 3 12.4.28 an powermail 12.5.1 without any problems.

It looks a lot, but it's not really complicated ;-)

Fell free to make your own PR or maybe https://github.com/mschwemer will do this. Would make me happy :-) BTW: What sense makes an event like *RenderViewEvent without any access to the view itself?

Greetings Harald

patch-issue-1053.patch

haraldwitt avatar Apr 16 '25 15:04 haraldwitt

I reopened the issue an will look again into this.

mschwemer avatar Apr 23 '25 16:04 mschwemer