Bug #81684

Flexform sections can't be created until content element is saved

Added by José Ricardo about 4 years ago. Updated 7 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
FormEngine aka TCEforms
Target version:
-
Start date:
2017-06-22
Due date:
% Done:

0%

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

Description

Hi,

I have a very simple flexform (attached) which adds a section to a tt_content record. If i try to add items on it before saving the content, it is not added and the on the browse console I can get the error:

#1476107295: PHP Warning: Invalid argument supplied for foreach() in .../typo3_src/typo3/sysext/backend/Classes/Form/Container/FlexFormElementContainer.php line 47 (More information)

TYPO3\CMS\Core\Error\Exception thrown in file
.../typo3_src/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 112.

Thought it was related to #80825, but the solution for it didn't solved this problem.
If the tt_content record is already saved, the items of section are added normally.
Other data not in sections works fine.

It works fine on TYPO3 7.

I've tested this on 8.7.1 and 8.7.2 and none works.


Files

Components.xml (1.73 KB) Components.xml José Ricardo, 2017-06-22 20:43
flexform_quickgooglemap.xml (10.1 KB) flexform_quickgooglemap.xml Fabian König, 2018-09-10 16:35
xdebug_add_datalayer.png (78.6 KB) xdebug_add_datalayer.png Tomas Norre Mikkelsen, 2021-02-23 13:11
Add_plugin_xdebug.png (8.75 KB) Add_plugin_xdebug.png Tomas Norre Mikkelsen, 2021-02-24 14:41
add_datalayer_before_safe.png (4.93 KB) add_datalayer_before_safe.png Tomas Norre Mikkelsen, 2021-02-24 14:41
#1

Updated by José Ricardo about 4 years ago

  • Related to Bug #80825: FlexForm Sections don't get saved before the parent record was stored to the DB added
#2

Updated by Fabian König about 3 years ago

I have the exact same error in Typo3 Version 8.7.10. See my flexform.xml attached.

Is there a fix avaiable? Otherwise flexform sections cannot be used productive as the editor has to always save a newly created content element to avoid this error.

#3

Updated by Fabian König about 3 years ago

  • Related to deleted (Bug #80825: FlexForm Sections don't get saved before the parent record was stored to the DB)
#4

Updated by Lorenz Ulrich almost 3 years ago

I have the same issue. Somehow it only seems to be an issue of you use type array. I will see what I find out.

#5

Updated by Lorenz Ulrich over 2 years ago

Did any of the watchers find a solution to this yet?

#6

Updated by Christian Eßl almost 2 years ago

  • Category set to FormEngine aka TCEforms
#7

Updated by Georg Ringer over 1 year ago

  • Status changed from New to Accepted

in 10.4-dev it adds an empty section header and fails to persist.

#8

Updated by Tomas Norre Mikkelsen 7 months ago

I'm experiencing this problem after updating from 7.6 as well.

If someone needs examples, this public extension of ours has the problem.
https://github.com/AOEpeople/TYPO3-Google-Tag-Manager

#9

Updated by Tomas Norre Mikkelsen 7 months ago

I'm not quite there yet, but to me, it looks like

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';

From "Configuration/TCA/Overrides/tt_content.php" isn't respected any more.
#10

Updated by Tomas Norre Mikkelsen 7 months ago

If I fake it and add it manually to

$GLOBALS["TCA"]["tt_content"]["types"]["list"]["showitem"] = $GLOBALS["TCA"]["tt_content"]["types"]["list"]["showitem"] . ',pi_flexform';

it works again. But I don't like the solution. The bug is still there.

#11

Updated by Tomas Norre Mikkelsen 7 months ago

Here is the change that removed the usages of

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']

https://review.typo3.org/c/Packages/TYPO3.CMS/+/41933/101/typo3/sysext/backend/Classes/Form/Container/FullRecordContainer.php#b59

#12

Updated by Tomas Norre Mikkelsen 7 months ago

Steps to reproduce the problem, I have choose TYPO3 8.7 for the steps as the extension I have the problem with is compatible with that.
The problem has been confirmed in newer TYPO3 version like 9.5 and 10.4 as well by me, but I don't have public extension to reference for that.

1. Start a TYPO3 Installaction (e.g. with DDEV) TYPO3 Version 8.7
2. Install https://github.com/AOEpeople/TYPO3-Google-Tag-Manager
3. Add following PageTS to a PageTS

# add GTM plugin to the content wizard
mod.wizards.newContentElement.wizardItems.plugins.elements.googletagmanager_datalayer {
    iconIdentifier = tx-google-tag-manager
    title = Plugins : Google Tag Manager
    description = Google Tag Manager Data Layer
    tt_content_defValues {
        CType = list
        list_type = googletagmanager_datalayer
    }
}

mod.wizards.newContentElement.wizardItems.plugins.show := addToList( googletagmanager_datalayer )

4. On the same page, add a new elment of the "Google Tag Manager", It's important that you select the "google tag manager" directly, so that the element will not be saved first.

5. Go to the plugin tab, and click "Add Datalayer", and you will see that and "foobar" element is added.

A work around is to save the element before clicking the "Add Datalayer" and after that the element will look correct when added.

#13

Updated by Tomas Norre Mikkelsen 7 months ago

I have created a V10 branch of the extension.
https://github.com/AOEpeople/TYPO3-Google-Tag-Manager/tree/tnm/v10test

It Can be that the extension isn't compatible with 10 LTS, but changing the composer.json and ext_emconf.php is enough to reproduce the problem in 10.4 as well.

#14

Updated by Tomas Norre Mikkelsen 7 months ago

In the first debug loop, when added the "Google Tag Manager" elmenet before switching to the profile tab, the "columnsToRemove" doesn't contain "pi_flexform", but when adding datalayer then it's part of "columnsToRemove".

#15

Updated by Georg Ringer 7 months ago

it works with the following flexform

<settingsdatalayervars>
                        <title>DataLayer Values:</title>
                        <type>array</type>
                        <section>1</section>
                        <el>
                            <datalayervar>
                                <type>array</type>
                                <title>DataLayer Value</title>
                                <el type="array">
                                    <label>
                                        <TCEforms>
                                            <label>Label:</label>
                                            <config>
                                                <type>input</type>
                                                <eval>trim</eval>
                                            </config>
                                        </TCEforms>
                                    </label>
                                    <value>
                                        <TCEforms>
                                            <label>Value:</label>
                                            <config>
                                                <type>input</type>
                                                <eval>trim</eval>
                                            </config>
                                        </TCEforms>
                                    </value>
                                </el>
                            </datalayervar>
                        </el>
                    </settingsdatalayervars>

it currently does not work with having settings.datalayersvars. so I guess it is again a missing escape thing

#16

Updated by Tomas Norre Mikkelsen 7 months ago

Thanks for your input Georg. It doesn't change anything in my setup.

Still failing the same way as before.

#17

Updated by Tomas Norre Mikkelsen 7 months ago

I tested with 10.4

#18

Updated by Tomas Norre Mikkelsen 7 months ago

I have made a small screencast with to show the problem
https://www.dropbox.com/s/a045mmnnm6k1m5h/flexform.mp4?dl=0

#19

Updated by Tomas Norre Mikkelsen 7 months ago

When adding the plugin at first, the default values are set.

But when the plugin is added, and pressing "add Datalayer" then the default values is empty, and therefore it's not added to the rendering.

URL from "add datalayer" button:
http://typo3test.ddev.site/typo3/index.php?route=/record/edit&token=26e48e0d68493dec0469b133cfa56ed790e1326a&edit[tt_content][1]=new&defVals[tt_content][colPos]=0&defVals[tt_content][sys_language_uid]=0&returnUrl=/typo3/index.php?route=%2Fmodule%2Fweb%2Flayout&token=7c490bc7d8a11f0e01428443b07ec05d38967c88&id=1&&defVals[tt_content][CType]=list&defVals[tt_content][list_type]=googletagmanager_datalayer

As we see, at least the returnUrl has some defVals defined, but as this commit:
https://github.com/TYPO3/TYPO3.CMS/commit/d29d4b5f7be4ec5d024b3d67e7e4abe97bbe4c46

It looks like it's fetched from somewhere else and not over the _GP anymore.

I'm not sure what the fix is, but I'm quite sure that this is the problem.
Please correct me if I'm wrong.

This is btw. from a TYPO3 10.4.13

#20

Updated by Tomas Norre Mikkelsen 7 months ago

I think I have located the Problem, but not the solution.

The $formDataCompilerInput['databaseRow'] is besides 'uid' empty, therefor there will never be found any default values for the list_type.

FormFlexAjaxController.php Line: 74

      $formDataCompilerInput = [
            'tableName' => $tableName,
            'vanillaUid' => (int)$vanillaUid,
            'command' => $command,
            'recordTypeValue' => $recordTypeValue,
            'processedTca' => $processedTca,
            'flexSectionContainerPreparation' => $flexSectionContainerPreparation,
        ];
        // A new container on a new record needs the 'NEW123' uid here, see comment
        // in DatabaseUniqueUidNewRow for more information on that.
        // @todo: Resolve, maybe with a redefinition of vanillaUid to transport the information more clean through this var?
        // @see issue #80100 for a series of changes in this area
        if ($command === 'new') {
            $formDataCompilerInput['databaseRow']['uid'] = $databaseRowUid;
        }
        $formData = $formDataCompiler->compile($formDataCompilerInput);

Therefore the flexform isn't added to the showItems

#21

Updated by Tomas Norre Mikkelsen 7 months ago

Adding this to the FlexFormAjaxController, solves the problem for me. I'll sleep on this over the weekend, and see if I find any problems or better approaches before I push it for review.

 if ($command === 'new') {
     $formDataCompilerInput['databaseRow']['uid'] = $databaseRowUid;
+    $dataStructureKey = $queryParameters['dataStructureIdentifier']['dataStructureKey'];
+    $subtypeValue = substr($dataStructureKey, 0, strpos($dataStructureKey, ','));
+    $formDataCompilerInput['databaseRow'][$processedTca['types'][$recordTypeValue]['subtype_value_field']] = $subtypeValue;
 }
#22

Updated by Gerrit Code Review 7 months ago

  • Status changed from Accepted to Under Review

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

Also available in: Atom PDF