Skip to content

Commit

Permalink
[BUGFIX] Allow creation of records after another
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bmack authored and andreaskienast committed Aug 30, 2018
1 parent 94a9901 commit 0e2756a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions typo3/sysext/backend/Classes/Controller/EditDocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2425,10 +2425,22 @@ public function localizationRedirect(ServerRequestInterface $request = null): ?R
*/
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()
Expand All @@ -2439,7 +2451,7 @@ protected function getLanguages(int $id, string $table): array
->where(
$queryBuilder->expr()->eq(
$GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
$queryBuilder->createNamedParameter($id, \PDO::PARAM_INT)
$queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)
)
)
->execute();
Expand Down

0 comments on commit 0e2756a

Please sign in to comment.