#102239Set default values for FlexForm fields
Description
Hi,
I’m trying to set a default value for a flexform field, but I don’t think it is currently possible, is it?
I tried using TCAdefaults with the syntax described here: https://docs.typo3.org/m/typo3/reference-tsconfig/main/en-us/PageTsconfig/TceForm.html but I think this only applies to TCEFORM and not TCAdefaults?
If this would work with TCAdefaults, how would it work with flexform sections? I tried to change a label for a field in a flexform section via TCEFORM but didn’t succeed.
Best regards
David
Reviews 2
History 24
-
Gerrit Code Review pushed patch set 1 for main to change 81548 status
NewUnder Review <span data-processor="relativetime" data-value="2023-10-25T13:45:27+00:00" > 10/25/23, 13:45 </span> -
Garvin Hicking commented <span data-processor="relativetime" data-value="2023-10-25T13:51:31+00:00" > 10/25/23, 13:51 </span>
-
Oliver Hader changed category <span data-processor="relativetime" data-value="2023-10-26T10:42:44+00:00" > 10/26/23, 10:42 </span>
-
Gerrit Code Review pushed patch set 1 for main to change 97426 <span data-processor="relativetime" data-value="2026-11-09T10:56:35+00:00" > 11/09/26, 10:56 </span>
*TL;DR:*
Yes, indeed using TCAdefaults for FlexForm fields is currently not possible. (You would need to adjust the
<default>attribute in the flexform for this.)Setting a label is possible via:
Now the in-depth take on this.
TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowInitializeNew::setDefaultsFromPageTsConfig()only interprets existing DB field names.The check is done on $result.processedTca.columns.XX – so you could only access “pi_flexform” here, but not “pi_flexform.yourKey”. Said
initializer doesn’t know about flexforms yet.
That is performed in
TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexProcessand you can actually see some documentation on its restrictions:https://github.com/TYPO3/typo3/blob/main/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaFlexProcess.php#L179
Now the problem within that Processor-Class is, that currently flexform operations don’t really distinguish between fetching the current value from the database,
or from a flexform-inherited default (at least to my casual interpretation).
Generally, operating on the result set within that Processor is a bit painful.
From what I’ve heard, work will be done in this are in v13, so this might be addressed.
I took a very deep dive into the rabbit hole and tried to patch it just for fun. I partially succeeded (see https://review.typo3.org/c/Packages/TYPO3.CMS/+/81548),
which allows one to set:
But sadly (due to the issues mentioned earlier) this override gets applied no matter if a record is fresh or read from the database, so that’s not a helpful state.