[BUGFIX] Allow creation of records after another 74/58074/5
authorBenni Mack <benni@typo3.org>
Thu, 30 Aug 2018 05:29:56 +0000 (07:29 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 30 Aug 2018 10:00:09 +0000 (12:00 +0200)
When adding a content element, EditDocumentController expects the id
for fetching being a positive page ID. This is however edgy as a
record (like tt_content) being added after another record receives
the negative ID of the previous record. So this needs to be resolved.

Resolves: #86010
Releases: master
Change-Id: I80d722a1603b8fa1d6ccb2fc2bb9c914ee38ee42
Reviewed-on: https://review.typo3.org/58074
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/backend/Classes/Controller/EditDocumentController.php

index 0125b60..9dafd4c 100644 (file)
@@ -2425,10 +2425,22 @@ class EditDocumentController
      */
     protected function getLanguages(int $id, string $table): array
     {
-        $site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId($id);
+        // This usually happens when a non-pages record is added after another, so we are fetching the proper page ID
+        if ($id < 0 && $table !== 'pages') {
+            $pageId = $this->pageinfo['uid'] ?? null;
+            if ($pageId !== null) {
+                $pageId = (int)$pageId;
+            } else {
+                $fullRecord = BackendUtility::getRecord($table, abs($id));
+                $pageId = (int)$fullRecord['pid'];
+            }
+        } else {
+            $pageId = $id;
+        }
+        $site = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId($pageId);
 
         // Fetch the current translations of this page, to only show the ones where there is a page translation
-        $allLanguages = $site->getAvailableLanguages($this->getBackendUser(), false, $id);
+        $allLanguages = $site->getAvailableLanguages($this->getBackendUser(), false, $pageId);
         if ($table !== 'pages' && $id > 0) {
             $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
             $queryBuilder->getRestrictions()->removeAll()
@@ -2439,7 +2451,7 @@ class EditDocumentController
                 ->where(
                     $queryBuilder->expr()->eq(
                         $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
-                        $queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
+                        $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
                     )
                 )
                 ->execute();