[BUGFIX] New values created by AddController are added correctly 46/53646/3
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 4 Aug 2017 14:55:25 +0000 (16:55 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Wed, 9 Aug 2017 08:04:48 +0000 (10:04 +0200)
New values created by AddController are now added again to the FlexForm
value by fixing the value parsing.

Additionally, the mixed up append/prepend values of `setValue` are fixed.

Resolves: #82049
Resolves: #82050
Releases: master, 8.7
Change-Id: Ifc2a4bf4ddd39a1b004db9945f832ca6cf9d765d
Reviewed-on: https://review.typo3.org/53646
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Sebastian Fischer <typo3@evoweb.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/Controller/Wizard/AddController.php

index 2b55abb..0e8a22c 100644 (file)
@@ -198,22 +198,30 @@ class AddController extends AbstractWizardController
                     // If the field is a flexForm field, work with the XML structure instead:
                     if ($this->P['flexFormPath']) {
                         // Current value of flexForm path:
-                        $currentFlexFormData = GeneralUtility::xml2array($currentParentRow[$this->P['field']]);
+                        $currentFlexFormData = $currentParentRow[$this->P['field']];
                         /** @var FlexFormTools $flexFormTools */
                         $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
-                        $currentFlexFormValue = $flexFormTools->getArrayValueByPath(
+                        $currentFlexFormValueByPath = $flexFormTools->getArrayValueByPath(
                             $this->P['flexFormPath'],
                             $currentFlexFormData
                         );
+
+                        // Compile currentFlexFormData to functional string
+                        $currentFlexFormValues = [];
+                        foreach ($currentFlexFormValueByPath as $value) {
+                            $currentFlexFormValues[] = $value['table'] . '_' . $value['uid'];
+                        }
+                        $currentFlexFormValue = implode(',', $currentFlexFormValues);
+
                         $insertValue = '';
                         switch ((string)$this->P['params']['setValue']) {
                             case 'set':
                                 $insertValue = $recordId;
                                 break;
-                            case 'prepend':
+                            case 'append':
                                 $insertValue = $currentFlexFormValue . ',' . $recordId;
                                 break;
-                            case 'append':
+                            case 'prepend':
                                 $insertValue = $recordId . ',' . $currentFlexFormValue;
                                 break;
                         }
@@ -236,10 +244,10 @@ class AddController extends AbstractWizardController
                             case 'set':
                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $recordId;
                                 break;
-                            case 'prepend':
+                            case 'append':
                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $currentValue . ',' . $recordId;
                                 break;
-                            case 'append':
+                            case 'prepend':
                                 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $recordId . ',' . $currentValue;
                                 break;
                         }