Project

General

Profile

Actions

Feature #102239

open

Set default values for FlexForm fields

Added by David Mellen 7 months ago. Updated 7 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2023-10-24
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

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

Actions #1

Updated by Gerrit Code Review 7 months ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/81548

Actions #2

Updated by Garvin Hicking 7 months ago

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.

Actions #3

Updated by Oliver Hader 7 months ago

  • Category set to FormEngine aka TCEforms
Actions

Also available in: Atom PDF