From 426384176fac1a40b92fe8321ad0eea7d70fb15c Mon Sep 17 00:00:00 2001
From: Georg Ringer <georg.ringer@gmail.com>
Date: Tue, 9 Jul 2024 22:31:46 +0200
Subject: [PATCH] [BUGFIX] Prevent multiple FlexContainers of same name

Extend the identifier used within the DOM by an additional field, as
already done in #97042 to make flexform sections within inline child
records work.

A styleguide example makes it easy to reproduce the edge case.

Resolves: #100937
Related: #97042
Releases: main, 12.4
Change-Id: I40120ea13b892c6387833dab444dad86951cf96f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85230
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
---
 .../Container/FlexFormSectionContainer.php    |  4 +--
 .../Configuration/FlexForms/SimpleSection.xml | 29 +++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 typo3/sysext/styleguide/Configuration/FlexForms/SimpleSection.xml

diff --git a/typo3/sysext/backend/Classes/Form/Container/FlexFormSectionContainer.php b/typo3/sysext/backend/Classes/Form/Container/FlexFormSectionContainer.php
index 49fd15d35211..bd215a36263b 100644
--- a/typo3/sysext/backend/Classes/Form/Container/FlexFormSectionContainer.php
+++ b/typo3/sysext/backend/Classes/Form/Container/FlexFormSectionContainer.php
@@ -71,8 +71,8 @@ class FlexFormSectionContainer extends AbstractContainer
             $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $flexFormContainerContainerResult);
         }
 
-        $containerId = sprintf('flexform-section-container-%s-%s-%s', $flexFormSheetName, $this->data['fieldName'], $flexFormFieldName);
-        $sectionContainerId = sprintf('flexform-section-%s-%s-%s', $flexFormSheetName, $this->data['fieldName'], $flexFormFieldName);
+        $containerId = sprintf('flexform-section-container-%s-%s-%s-%s', $flexFormSheetName, $this->data['fieldName'], $flexFormFieldName, md5($this->data['elementBaseName']));
+        $sectionContainerId = sprintf('flexform-section-%s-%s-%s-%s', $flexFormSheetName, $this->data['fieldName'], $flexFormFieldName, md5($this->data['elementBaseName']));
         $hashedSectionContainerId = 'section-' . md5($sectionContainerId);
 
         // "New container" handling: Creates buttons for each possible container with all relevant information for the ajax call.
diff --git a/typo3/sysext/styleguide/Configuration/FlexForms/SimpleSection.xml b/typo3/sysext/styleguide/Configuration/FlexForms/SimpleSection.xml
new file mode 100644
index 000000000000..140c18626552
--- /dev/null
+++ b/typo3/sysext/styleguide/Configuration/FlexForms/SimpleSection.xml
@@ -0,0 +1,29 @@
+<T3DataStructure>
+    <sheets>
+        <sDEF>
+            <ROOT>
+                <type>array</type>
+                <el>
+                    <answers>
+                        <type>array</type>
+                        <section>1</section>
+                        <el>
+                            <answer>
+                                <type>array</type>
+                                <title>Answer</title>
+                                <el>
+                                    <text>
+                                        <label>Text</label>
+                                        <config>
+                                            <type>input</type>
+                                        </config>
+                                    </text>
+                                </el>
+                            </answer>
+                        </el>
+                    </answers>
+                </el>
+            </ROOT>
+        </sDEF>
+    </sheets>
+</T3DataStructure>
-- 
GitLab