[BUGFIX] Ensure correct initialization of selectTree value 15/60415/3
authorNicole Cordes <typo3@cordes.co>
Mon, 8 Apr 2019 16:27:08 +0000 (18:27 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Wed, 15 May 2019 19:20:57 +0000 (21:20 +0200)
This patch provides the current set database value in a hidden field as
early as the whole select tree JavaScript is provided. This prevents
data loss if the current record is saved before the select tree was loaded.

Resolves: #86954
Releases: master, 9.5, 8.7
Change-Id: I467b2a52d34b806713cd201a8a2a4f9bb8e92c71
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60415
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Form/Element/SelectTreeElement.php
typo3/sysext/backend/Classes/Form/FormDataProvider/TcaSelectTreeItems.php

index 67b73dd..074a599 100644 (file)
@@ -164,7 +164,7 @@ class SelectTreeElement extends AbstractFormElement
         $html[] =                       ' data-tree-show-toolbar="' . $showHeader . '"';
         $html[] =                       ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
         $html[] =                       ' id="treeinput' . $formElementId . '"';
-        $html[] =                       ' value=""';
+        $html[] =                       ' value="' . htmlspecialchars(implode(',', $parameterArray['itemFormElValue'])) . '"';
         $html[] =                   '/>';
         $html[] =               '</div>';
         $html[] =               '<div id="' . $treeWrapperId . '" class="svg-tree-wrapper" style="height: ' . $heightInPx . 'px;"></div>';
index 1da6d7a..05ebeb8 100644 (file)
@@ -82,11 +82,12 @@ class TcaSelectTreeItems extends AbstractItemProvider implements FormDataProvide
                 }
             }
 
-            if ($result['selectTreeCompileItems']) {
-                // Prepare the list of currently selected nodes using RelationHandler
-                $result['databaseRow'][$fieldName] = $this->processDatabaseFieldValue($result['databaseRow'], $fieldName);
-                $result['databaseRow'][$fieldName] = $this->processSelectFieldValue($result, $fieldName, []);
+            // Prepare the list of currently selected nodes using RelationHandler
+            // This is needed to ensure a correct value initialization before the actual tree is loaded
+            $result['databaseRow'][$fieldName] = $this->processDatabaseFieldValue($result['databaseRow'], $fieldName);
+            $result['databaseRow'][$fieldName] = $this->processSelectFieldValue($result, $fieldName, []);
 
+            if ($result['selectTreeCompileItems']) {
                 $finalItems = [];
 
                 // Prepare the list of "static" items if there are any.