#107152Frontend error message (Serialization of 'Closure' is not allowed) for Extbase plugins with FlexForm TCA field configurations which load data from DB
Description
If an Extbase plugin is not supposed to be cashed and this is done via a FlexForm configuration with TCA fields that are based on database queries, an error is displayed in the frontend.
ExtensionUtility::configurePlugin(
'Plugin',
'PluginForm',
[
PluginController::class => 'searchForm',
],
[
PluginController::class => 'searchForm',
],
ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
);
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<general>
<ROOT>
<sheetTitle>LLL:EXT:plugin/Resources/Private/Language/locallang_db.xml:flexform.pi1.sDEF</sheetTitle>
<el>
<persistence.storagePid>
<label>LLL:EXT:plugin/Resources/Private/Language/locallang_db.xml:flexform.pi1.storagePid</label>
<config>
<type>group</type>
<size>5</size>
<allowed>pages</allowed>
<internal_type>db</internal_type>
<maxitems>99</maxitems>
<minitems>0</minitems>
<show_thumbs>1</show_thumbs>
<wizards>
<suggest>
<type>suggest</type>
</suggest>
</wizards>
</config>
</persistence.storagePid>
</el>
</ROOT>
</general>
</sheets>
</T3DataStructure>Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
Related issues 1
Files 2
History 8
-
Garvin Hicking commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2025-07-28T08:27:36+00:00" > 07/28/25, 08:27 </span> -
Reto Gehrig commented and changed attached extbase_test_0.0.0_202507281152.zip <span data-processor="relativetime" data-value="2025-07-28T10:00:38+00:00" > 07/28/25, 10:00 </span>
Here’s a small Extbase test extension with three configuration options.
The error occurs as soon as the “Extbase Test – no Cache” plugin, which is not cached, is activated. This occurs in two different Typo3 13.4.15 installations.
This also affects the “news_searchform” plugin in the “News” extension.
Thanks for your support.
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-28T10:34:11+00:00" > 07/28/25, 10:34 </span>
Thanks for the extension. I installed it into a v14 and v13 instance and in both cases the frontend displays the plugin just fine for me.
Can you please check this with a totally vanilla TYPO3 installation please?
Also, the full stacktrace would maybe help to see which “route” your setup goes here (I am unsure where exactly the “closure” comes into play, I kind of have the feeling that could come from an extension/custom code).
-
Reto Gehrig commented <span data-processor="relativetime" data-value="2025-07-28T15:05:30+00:00" > 07/28/25, 15:05 </span>
Thanks for your tips. I was able to narrow down the error and find it in an extension. An “AfterContentHasBeenFetchedEventListener” was initiated in the “page-content” data processor, which converted the TYPO3\CMS\Core\Domain\Record element into an array and added another field.
This caused the error. -
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-28T15:25:45+00:00" > 07/28/25, 15:25 </span>
Great, thanks for the investigation. Are you able to solve the issue with this or how could we address this?
-
Reto Gehrig commented <span data-processor="relativetime" data-value="2025-08-06T19:08:48+00:00" > 08/06/25, 19:08 </span>
Garvin Hicking wrote in #note-5:
> Great, thanks for the investigation. Are you able to solve the issue with this or how could we address this?It seems that the EventListener “AfterContentHasBeenFetchedEventListener” is causing the problem when editing the data. This is something related to caching. I’ve now implemented the extension without the “AfterContentHasBeenFetchedEventListener”.
-
Georg Ringer changed Related to #109358 <span data-processor="relativetime" data-value="2026-10-02T11:53:43+00:00" > 10/02/26, 11:53 </span>
-
Georg Ringer commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-10-02T11:54:49+00:00" > 10/02/26, 11:54 </span>Thanks for tracking this down! For anyone running into the same exception, here is what happens and how to add custom fields without breaking uncached plugins.
Why the listener causes the exception
- The
page-contentdata processor provides the content elements asRecordobjects. When they are rendered via<f:cObject ... data="{record}" />,f:cObjectconverts aRecordinto its raw database row, which only contains scalar values. - Converting the records into arrays in an
AfterContentHasBeenFetchedEventlistener via$record->toArray()changes that.toArray()resolves the lazy properties of the record itself, but relations (LazyRecordCollection, file references, nested records) stay objects which contain closures. f:cObjectnow receives an array instead of a record, so the conversion to the raw row does not happen and these objects end up in$cObj->data.- An uncached Extbase action turns the plugin into a
USER_INT. For that, the state of theContentObjectRendereris serialized into the page cache, and serializing the closures fails with “Serialization of ‘Closure’ is not allowed”.
That is why only the uncached plugin was affected and why it could not be reproduced without the listener.
How to add a custom field instead
Keep the records as
Recordobjects. To add or change a property, use theRecordCreationEvent, which is available in v13.4 as well:use TYPO3\CMS\Core\Attribute\AsEventListener; use TYPO3\CMS\Core\Domain\Event\RecordCreationEvent; final class AddCustomFieldToContentRecord { #[AsEventListener] public function __invoke(RecordCreationEvent $event): void { if ($event->getSchema()->getName() !== 'tt_content') { return; } $event->setProperty('my_custom_field', 'some value'); } }The
AfterContentHasBeenFetchedEventis meant to filter or reorder the fetched content (see the example in the changelog of #105638), not to replace the records with arrays.The same cause, objects in the data of an uncached content object, was also reported in #109358.
As the issue is caused by custom code and you already solved it, I’m closing it. Thanks again!
- The
Hi!
I cannot reproduce this, I setup an example plugin like this: https://github.com/garvinhicking/extbase_upload/commit/5985da8718406e8a2e5c6c94d876e8c15bc1ae4f
Can you please give more instructions with a concrete implementation maybe that allows to reproduce this?
Sadly I’m not sure what you could mean with “configuration with TCA fields that are based on database queries”. If you modify TCA dynamically, how exactly do you do it? You should do it like EXT:contentblocks in this case to ensure everything is cachable and you do modifications with PSR events and/or early enough in the middlewares.