Issue Bug Under Review Stale

#110192Undefined array key in FormFlexAjaxController::containerAdd() on new records

Martina Kratky 07/13/26, 11:12 updated 09/09/26, 05:36

Description

Summary

Adding an item to a FlexForm `section/container` field fails on a new, unsaved record when the field’s data structure is resolved per-CType via `ds_pointerField`. `FormFlexAjaxController::containerAdd()` resolves the structure via `databaseRow.CType`, which is never populated for new records, so it falls back to the generic “default” structure – missing the CType-specific fields, hence the warning. No dot-notation needed to reproduce, so this is independent of the accordion fix already merged for #109727.

Steps to reproduce

Register a new `tt_content` CType with its own FlexForm data structure via the classic `ds_pointerField` pattern:

$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds_pointerField'] = 'CType';
$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['my_ctype'] = 'FILE:EXT:my_ext/Configuration/FlexForms/MyFlexForm.xml';
where MyFlexForm.xml defines a
with at least one <container> (e.g. a repeatable link field) – identifier without any dot, e.g. just <section>. Then: <ol> <li>Create a new `tt_content` record with `CType = my_ctype`, don’t save.</li> <li>Click “Add” on the section field.</li> </ol> <p><strong>Expected</strong> : new container item added.</p> <p><strong>Actual</strong> : uncaught promise rejection in console; PHP warning Undefined array key “<fieldname>“ at `FormFlexAjaxController.php:94`.</fieldname></p> <p><strong>Workaround</strong> : save the record once, then it works.</p> <h2>Root cause</h2> <p>Compared the actual installed code of the same project on v12.4 vs. v14: in v12.4, the client sends an already-resolved dataStructureIdentifier (computed while CType was still known), and the controller force-sets it into `$processedTca` via `FlexFormTools::parseDataStructureByIdentifier()` before compiling – so `databaseRow.CType`never matters. In v14, this mechanism was removed on both JS and PHP side; resolution now depends solely on `databaseRow.CType`, which stays empty for new records. Looks like an unintentional v12→v14 regression, separate from the Bootstrap Collapse change (#109267) that caused the toggle issue in #109727.</p> <h2>Suggested fix</h2> <p>Seed `databaseRow[$typeField]` from the already-available recordTypeValue inside the `command === ‘new’` branch:</p> <p>
if ($command === 'new') {
    $formDataCompilerInput['databaseRow']['uid'] = $databaseRowUid;
    $typeField = $processedTca['ctrl']['type'] ?? null;
    if ($typeField !== null && $recordTypeValue !== '') {
        $formDataCompilerInput['databaseRow'][$typeField] = $recordTypeValue;
    }
}
</p></section></container>

Reviews 1

History 24