Project

General

Profile

Actions

Bug #103885

open

foreign_match_fields is ignored in flexforms in Typo3 12

Added by Georgi Mateev 9 months ago. Updated 11 days ago.

Status:
Accepted
Priority:
Must have
Assignee:
-
Category:
System/Bootstrap/Configuration
Target version:
-
Start date:
2024-05-23
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

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.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #99756: Move TcaMigration to FlexFormProcessorClosed2023-01-30

Actions
Actions #1

Updated by Christian Kuhn 9 months ago

  • Related to Bug #99756: Move TcaMigration to FlexFormProcessor added
Actions #2

Updated by Georg Ringer 7 months ago · Edited

  • Status changed from New to Accepted

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>
                    ',
                ],
            ],
        ],
Actions #3

Updated by Garvin Hicking 6 months ago

  • Category set to System/Bootstrap/Configuration
Actions #4

Updated by Lorenz Ulrich 3 months ago

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

Actions #5

Updated by Mike Street 2 months ago

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 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]';
Actions #6

Updated by Lorenz Ulrich 19 days ago

@Oliver Bartsch and @Benni Mack: 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?

Actions #7

Updated by Loon Buster 14 days ago

  • Priority changed from Should have to Must have

BUG.

Actions #8

Updated by Loon Buster 11 days ago

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

Actions

Also available in: Atom PDF