Issue Bug Closed

#103885foreign_match_fields is ignored in flexforms in Typo3 12

Georgi Mateev 05/23/24, 12:05 updated 12/02/25, 14:33

Description

The inline TCA type (also tested for the new file type) does not respect the configuration foreign_match_fields.fieldname when in Flexform context. Up to TYPO3 v11 it would respect it and store the value in the sys_file_reference table. After updating to TYPO3 v12 it does not respect it anymore and writes the name of the TCA Field instead.

Example:

<settings.thumbnailImages>
                        <label>LLL:EXT:sg_vimeo/Resources/Private/Language/locallang.xlf:flexform.thumbnailImages
                        </label>
                        <description>
                            LLL:EXT:sg_vimeo/Resources/Private/Language/locallang.xlf:flexform.thumbnailImages.description
                        </description>
                        <config>
                            <type>inline</type>
                            <foreign_table>sys_file_reference</foreign_table>
                            <foreign_field>uid_foreign</foreign_field>
                            <foreign_table_field>tablenames</foreign_table_field>
                            <foreign_label>uid_local</foreign_label>
                            <foreign_sortby>sorting_foreign</foreign_sortby>
                            <foreign_selector>uid_local</foreign_selector>
                            <foreign_selector_fieldTcaOverride type="array">
                                <config>
                                    <appearance>
                                        <elementBrowserType>file</elementBrowserType>
                                        <elementBrowserAllowed>jpg,png,svg,jpeg,gif,webp</elementBrowserAllowed>
                                    </appearance>
                                </config>
                            </foreign_selector_fieldTcaOverride>
                            <foreign_match_fields type="array">
                                <fieldname>tx_sgvimeo_thumbnail_image</fieldname>
                            </foreign_match_fields>
                            <filter type="array">
                                <userFunc>TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter->filterInlineChildren
                                </userFunc>
                                <parameters>
                                    <allowedFileExtensions>jpg,png,svg,jpeg,gif,webp</allowedFileExtensions>
                                    <disallowedFileExtensions></disallowedFileExtensions>
                                </parameters>
                            </filter>
                            <appearance type="array">
                                <useSortable>1</useSortable>
                                <headerThumbnail>
                                    <field>uid_local</field>
                                    <height>45m</height>
                                </headerThumbnail>
                                <enabledControls>
                                    <info>1</info>
                                    <new>0</new>
                                    <dragdrop>1</dragdrop>
                                    <sort>1</sort>
                                    <hide>1</hide>
                                    <delete>1</delete>
                                </enabledControls>
                            </appearance>
                            <overrideChildTca>
                                <columns type="array">
                                    <uid_local type="array">
                                        <config type="array">
                                            <appearance type="array">
                                                <elementBrowserType>file</elementBrowserType>
                                                <elementBrowserAllowed>jpg,png,svg,jpeg,gif</elementBrowserAllowed>
                                            </appearance>
                                        </config>
                                    </uid_local>
                                    <crop type="array">
                                        <config type="array">
                                            <cropVariants type="array">
                                                <medium type="array">
                                                    <disabled>1</disabled>
                                                </medium>
                                                <small type="array">
                                                    <disabled>1</disabled>
                                                </small>
                                                <extrasmall type="array">
                                                    <disabled>1</disabled>
                                                </extrasmall>
                                            </cropVariants>
                                        </config>
                                    </crop>
                                </columns>
                                <types type="array">
                                    <numIndex index="2">
                                        <showitem>
                                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,--palette--;;filePalette
                                        </showitem>
                                    </numIndex>
                                </types>
                            </overrideChildTca>
                        </config>
                    </settings.thumbnailImages>

Expected result in the database:
tx_sgvimeo_thumbnail_image

Actual result in the database:
settings.thumbnailImages

You can test this with our sgalinski/sg-vimeo extension in version 7.1.11 when trying to set a custom thumbnail image.

This looks like a bug in TYPO3 12 or an undocumented breaking change.

Reviews 3

History 1417

  1. Georg Ringer commented and changed status New Accepted <span data-processor="relativetime" data-value="2024-07-12T18:41:43+00:00" > 07/12/24, 18:41 </span>

    problem is in \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools::migrateFlexField calls $this->tcaMigration->migrate which removes with unset $fieldConfig['config']['foreign_match_fields'] and in \TYPO3\CMS\Core\Configuration\Tca\TcaPreparation::configureFileReferences it is set by default to the fieldname

    can be reproduced in v13 in tx_styleguide_flex with

    'flex_4' => [
                'label' => 'flex_4',
                'config' => [
                    'type' => 'flex',
                    'ds' => [
                        'default' => '
                            <T3DataStructure>
                                <sheets>
                                    <sInline>
                                        <ROOT>
                                            <sheetTitle>inline</sheetTitle>
                                            <type>array</type>
                                            <el>
                                              <settings.thumbnailImages>
                            <label>xxxx</label>
                            <description>
                                LLL:EXT:sg_vimeo/Resources/Private/Language/locallang.xlf:flexform.thumbnailImages.description
                            </description>
                            <config>
                                <type>inline</type>
                                <foreign_table>sys_file_reference</foreign_table>
                                <foreign_field>uid_foreign</foreign_field>
                                <foreign_table_field>tablenames</foreign_table_field>
                                <foreign_label>uid_local</foreign_label>
                                <foreign_sortby>sorting_foreign</foreign_sortby>
                                <foreign_selector>uid_local</foreign_selector>
                                <foreign_selector_fieldTcaOverride type="array">
                                    <config>
                                        <appearance>
                                            <elementBrowserType>file</elementBrowserType>
                                            <elementBrowserAllowed>jpg,png,svg,jpeg,gif,webp</elementBrowserAllowed>
                                        </appearance>
                                    </config>
                                </foreign_selector_fieldTcaOverride>
                                <foreign_match_fields type="array">
                                    <fieldname>tx_sgvimeo_thumbnail_image</fieldname>
                                </foreign_match_fields>
                                <filter type="array">
                                    <userFunc>TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter->filterInlineChildren
                                    </userFunc>
                                    <parameters>
                                        <allowedFileExtensions>jpg,png,svg,jpeg,gif,webp</allowedFileExtensions>
                                        <disallowedFileExtensions></disallowedFileExtensions>
                                    </parameters>
                                </filter>
                                <appearance type="array">
                                    <useSortable>1</useSortable>
                                    <headerThumbnail>
                                        <field>uid_local</field>
                                        <height>45m</height>
                                    </headerThumbnail>
                                    <enabledControls>
                                        <info>1</info>
                                        <new>0</new>
                                        <dragdrop>1</dragdrop>
                                        <sort>1</sort>
                                        <hide>1</hide>
                                        <delete>1</delete>
                                    </enabledControls>
                                </appearance>
                                <overrideChildTca>
                                    <columns type="array">
                                        <uid_local type="array">
                                            <config type="array">
                                                <appearance type="array">
                                                    <elementBrowserType>file</elementBrowserType>
                                                    <elementBrowserAllowed>jpg,png,svg,jpeg,gif</elementBrowserAllowed>
                                                </appearance>
                                            </config>
                                        </uid_local>
    
                                    </columns>
    
                                </overrideChildTca>
                            </config>
                        </settings.thumbnailImages>
                                            </el>
                                        </ROOT>
                                    </sInline>
    
                                </sheets>
                            </T3DataStructure>
                        ',
                    ],
                ],
            ],
  2. Lorenz Ulrich commented <span data-processor="relativetime" data-value="2024-11-13T10:27:32+00:00" > 11/13/24, 10:27 </span>

    @just2b As you also seem to have this problem, do you know what the way forward would be here?

  3. Mike Street commented <span data-processor="relativetime" data-value="2024-11-25T14:38:34+00:00" > 11/25/24, 14:38 </span>

    I’ve just encountered the same problem with an upgrade to 12.

    I assume code has changed since @just2b’s investigations as I wasn’t able to find his referenced code, however I was able to locate the issue in

    TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools

    Specifically, in the `prepareFileFields` method – at lines 1026-1039 GitHub link(on the 12.4 branch)

    It seems that this array_replace_recursive replaces all the settings in the original config regardless of if it is set. I assume it is providing a fallback to ensure everything is correct.

    To solve, it either needs to do a check to see if the array key exists or, with my quick tests, swap the parameters to provide the defaults first:

    $fieldConfig['config'] = array_replace_recursive(
        [
            'foreign_table' => 'sys_file_reference',
            'foreign_field' => 'uid_foreign',
            'foreign_sortby' => 'sorting_foreign',
            'foreign_table_field' => 'tablenames',
            'foreign_match_fields' => [
                'fieldname' => $fieldName,
            ],
            'foreign_label' => 'uid_local',
            'foreign_selector' => 'uid_local',
        ],
        $fieldConfig['config']
    );

    As I say, this was only checked on my specific install with some debug’s thrown around so would need verifying.

    —-

    As an interim solution, I updated my FlexForm field to use the field name (e.g. settings.background) to ensure backwards compatibility once this fix rolls out and then using the following SQL to identify what will be affected and what needs updating

    Example SQL – not to be copied and run directly

    To get an idea of what items are affected

    SELECT sfr.tablenames, sfr.fieldname, ttc.uid, ttc.CType
    FROM sys_file_reference AS sfr
    LEFT JOIN tt_content AS ttc ON sfr.uid_foreign = ttc.uid
    WHERE sfr.fieldname = 'background'
    AND sfr.tablenames = 'tt_content'
    AND CType = '[your ctype]';
  4. Lorenz Ulrich commented <span data-processor="relativetime" data-value="2025-01-19T21:11:03+00:00" > 01/19/25, 21:11 </span>

    obartsch and benni: Since you are the creators of the code in question here: Can I assume that the possibility to use `foreign_match_fields` in a FlexForm of type file was just removed (which would be an undocumented breaking change) or do you consider it a bug?

  5. Loon Buster commented and changed priority Should have Must have <span data-processor="relativetime" data-value="2025-01-24T19:33:17+00:00" > 01/24/25, 19:33 </span>

    BUG.

  6. Loon Buster commented <span data-processor="relativetime" data-value="2025-01-27T20:18:54+00:00" > 01/27/25, 20:18 </span>

    In TYPO3 v12, the foreign_match_fields configuration in FlexForms is removed during the TCA migration. This happens in the TcaMigration::migrate method, where the field is deleted using unset($fieldConfig[‘config’][‘foreign_match_fields’]);. Additionally, the value is no longer stored in the fieldname field of the sys_file_reference table. This results in the loss of custom mappings that previously played a crucial role in FlexForm and file assignments.

    The functionality of foreign_match_fields or fieldname allowed for specific and unique mappings to be stored in the sys_file_reference table. These mappings are essential for maintaining a robust and flexible data structure—independent of extensions or modifications to the FlexForm files. The removal of this configuration leads to significant limitations, especially in scenarios that require flexibility and adaptability. It also complicates the visibility and traceability of mappings within the database.

    Why isn’t the fieldname field offered as an alternative option? Such a choice would allow developers to decide between using the standard automation or a customized flexibility. This would not only secure existing use cases but also significantly enhance developer-friendliness and transparency.

    .loon

  7. Cyril Janody commented <span data-processor="relativetime" data-value="2025-05-29T17:35:55+00:00" > 05/29/25, 17:35 </span>

    Hi guys,

    Is there a plan to solve this issue or is this a breaking change?

    Thank you :)

  8. Gerrit Code Review pushed patch set 1 for main to change 89593 status Accepted Under Review <span data-processor="relativetime" data-value="2025-05-30T07:55:17+00:00" > 05/30/25, 07:55 </span>

  9. Oliver Bartsch commented <span data-processor="relativetime" data-value="2025-05-30T16:12:42+00:00" > 05/30/25, 16:12 </span>

    Hi,

    I’m really sorry for the late reply. You’re absolutely right — this does appear to be a bug, and I’ve now provided a fix for it. Thanks a lot for reporting it! I’d be grateful if you could take a moment to review the patch.

    Best,
    Oli

  10. Cyril Janody commented <span data-processor="relativetime" data-value="2025-05-30T16:42:16+00:00" > 05/30/25, 16:42 </span>

    Hi,

    Looks good to me.

    Thank you very much for the patch.

    Have a nice weekend!

    Cyril

  11. Oliver Bartsch commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-05-31T09:35:08+00:00" > 05/31/25, 09:35 </span>

    Applied in changeset commit:15ebc9787d1839679c179433423b76de03412f89.