[BUGFIX] Set correct record information for SaveAndNew 50/47350/2
authorNicole Cordes <typo3@cordes.co>
Mon, 7 Mar 2016 20:02:43 +0000 (21:02 +0100)
committerBenni Mack <benni@typo3.org>
Mon, 21 Mar 2016 21:54:47 +0000 (22:54 +0100)
This patch ensures the correct record information for saving and
inserting a new record even in a workspace.

Resolves: #70542
Releases: master, 7.6
Change-Id: I3b88b08a55600f8c7bc5e2c2f05444624181db83
Reviewed-on: https://review.typo3.org/47350
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php

index fd86b11..38cb14c 100644 (file)
@@ -648,14 +648,35 @@ class EditDocumentController extends AbstractModule
                 // Finding the first id, getting the records pid+uid
                 reset($this->editconf[$nTable]);
                 $nUid = key($this->editconf[$nTable]);
-                $nRec = BackendUtility::getRecord($nTable, $nUid, 'pid,uid');
+                $recordFields = 'pid,uid';
+                if (!empty($GLOBALS['TCA'][$nTable]['ctrl']['versioningWS'])) {
+                    $recordFields .= ',t3ver_oid';
+                }
+                $nRec = BackendUtility::getRecord($nTable, $nUid, $recordFields);
+                // Determine insertion mode ('top' is self-explaining,
+                // otherwise new elements are inserted after one using a negative uid)
+                $insertRecordOnTop = ($this->getNewIconMode($nTable) == 'top');
                 // Setting a blank editconf array for a new record:
                 $this->editconf = array();
-                if ($this->getNewIconMode($nTable) == 'top') {
-                    $this->editconf[$nTable][$nRec['pid']] = 'new';
+                // Determine related page ID for regular live context
+                if ($nRec['pid'] != -1) {
+                    if ($insertRecordOnTop) {
+                        $relatedPageId = $nRec['pid'];
+                    } else {
+                        $relatedPageId = -$nRec['uid'];
+                    }
+                // Determine related page ID for workspace context
                 } else {
-                    $this->editconf[$nTable][-$nRec['uid']] = 'new';
+                    if ($insertRecordOnTop) {
+                        // Fetch live version of workspace version since the pid value is always -1 in workspaces
+                        $liveRecord = BackendUtility::getRecord($nTable, $nRec['t3ver_oid'], $recordFields);
+                        $relatedPageId = $liveRecord['pid'];
+                    } else {
+                        // Use uid of live version of workspace version
+                        $relatedPageId = -$nRec['t3ver_oid'];
+                    }
                 }
+                $this->editconf[$nTable][$relatedPageId] = 'new';
                 // Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
                 $this->R_URL_getvars['edit'] = $this->editconf;
                 // Re-compile the store* values since editconf changed...