[TYPO3-mvc] Re: FormViewHelper - Serialization of 'Closure' is not allowed

Viktor Livakivskyi invisible.kinder at gmail.com
Mon Sep 14 19:03:06 CEST 2015


Hi, List.

Bumping this old topic, which is still actual in TYPO3 7.4.

> My solution will break as soon as it is necessary to rebuild the 
> referring request in Tx_Extbase_MVC_Web_Request - which happens when a 
> validation fails.

I have exactly same issue.
Here is a problem:
1. User submits a code via form to proxyAction(Code $code).
2. Based on user's input, proxyAction() forwards the flow either to firstVariantAction(Code $code) or to secondVariantAction(Code $code).
3. Exception "Serialization of 'Closure' is not allowed" is thrown.
4. Added __sleep() method on my Code model, which returns $this->activationCode;
5. Works!
6. On second step form (firstVariantAction()) added hidden input field with 'activationCode' and text field 'activationSource', which shouldn't be empty. Form action is saveFirstVariantAction(Code $code);
7. Submitting with 'activationSource'  not empty - all is OK.
8. Submitting with 'activationSource'  *empty* - Fatal Error is thrown: "Argument 1 passed to MyController::firstVariantAction() must be an instance of Code, null given"

Reason: in case of validation error (e.g. empty field), errorAction() is triggered, which tries to fetch arguments from referring request and redirects to it. The problem is, that when serialize() is executed in FromViewHelper, for whatever reason it doesn't use result of __sleep() call from my model and stores encoded version of "a:1:{s:4:"code";N;}". So, on unserialization in referring request this information is lost.

Possible fix: allow NULL in action, to which action was forwarded: firstVariantAction(Code $code = NULL)

This solution seems hacky for me.
Moreover, __wakeup() of AbstractDomainObject says, that this method "@deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Objects are instantiated differently calling parent::__wakeup() is no longer necessary."

So, the question: is it possible to forward not yet persisted object from one action to another without some hacks with __sleep() and NULLs?

TYPO3 7.4
PHP 5.6


More information about the TYPO3-project-typo3v4mvc mailing list