From 10bcd26c93595ca9a60e07349800d0dbb8e534c5 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 29 Apr 2021 20:25:03 +0200
Subject: [PATCH] [BUGFIX] Apply TCAdefaults to DataHandler if FormEngine was
 not used before

If TCAdefaults.pages.categories = 4 is used in userTSconfig, and a new
page is created via Drag&Drop or via "Create Multiple New Pages" via
ClickMenu, TCAdefaults are now added to the incomingFieldArray and
not just the fieldArray.

This is also great for translations (using "Just Localized"(tm) technology),
where the defaults are respected as well now.

Resolves: #92146
Resolves: #77847
Related: #89211
Releases: master, 10.4
Change-Id: I87a2f2d486831f9bda9a979c4ff99d4e8b2ada2f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/68918
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Guido Schmechel <guido.schmechel@brandung.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: Benni Mack <benni@typo3.org>
---
 typo3/sysext/core/Classes/DataHandling/DataHandler.php | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
index 240f18146d85..e2949593764a 100644
--- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php
+++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php
@@ -1068,6 +1068,11 @@ class DataHandler implements LoggerAwareInterface
                             (int)$this->BE_USER->firstMainGroup
                         );
                     }
+                    // Ensure that the default values, that are stored in the $fieldArray (built from internal default values)
+                    // Are also placed inside the incomingFieldArray, so this is checked in "fillInFieldArray" and
+                    // all default values are also checked for validity
+                    // This allows to set TCAdefaults (for example) without having to use FormEngine to have the fields available first.
+                    $incomingFieldArray = array_replace_recursive($fieldArray, $incomingFieldArray);
                 }
                 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
                 $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
-- 
GitLab