Issue Feature Under Review

#102239Set default values for FlexForm fields

David Mellen 10/24/23, 07:54 updated 11/09/26, 10:56

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

  1. Garvin Hicking commented <span data-processor="relativetime" data-value="2023-10-25T13:51:31+00:00" > 10/25/23, 13:51 </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:

    TCEFORM.tt_content.pi_flexform.ghsvgcrop_svgcropdemo.sDEF.settings\.subtitle.label=Your custom label

    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\TcaFlexProcess and 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:

    TCAdefaults.tt_content.pi_flexform.settings\.subtitle=My override value

    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.