Skip to content

Commit

Permalink
[BUGFIX] Correct link in PageMovingPagePositionMap
Browse files Browse the repository at this point in the history
Repositioning a content element to a different page
using the list module "Re-position content element"
view fails with a broken "backend-in-backend" link.

The patch avoids linkThisScript() by handing the request
around and creates the url using the UriBuilder instead.

Note the construct is one of the few left over controllers
that have not been refactored yet. This should happen in
v13, together with re-thinking the view along the way.

Resolves: #100564
Releases: main
Change-Id: Ib912e878647ea778ecc941a185f73d9e835059a1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78598
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
lolli42 authored and bmack committed Apr 12, 2023
1 parent e207344 commit 4a36f6d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface
$this->getButtons($view);
// Build the <body> for the module
$view->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_misc.xlf:movingElement'));
$view->assignMultiple($this->getContentVariables());
$view->assignMultiple($this->getContentVariables($request));
return $view->renderResponse('ContentElement/MoveElement');
}

/**
* Assign main body content to view.
*/
protected function getContentVariables(): array
protected function getContentVariables(ServerRequestInterface $request): array
{
if (!$this->page_id) {
return [];
Expand Down Expand Up @@ -127,7 +127,7 @@ protected function getContentVariables(): array
}
}
// Create the position tree:
$assigns['positionTree'] = $pagePositionMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
$assigns['positionTree'] = $pagePositionMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI, $request);
break;
case 'tt_content':
// Initialize the content position map:
Expand Down Expand Up @@ -158,7 +158,7 @@ protected function getContentVariables(): array
}
// Create the position tree (for pages) without insert lines:
$pagePositionMap->dontPrintPageInsertIcons = 1;
$assigns['positionTree'] = $pagePositionMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
$assigns['positionTree'] = $pagePositionMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI, $request);
}
}
return $assigns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public function newPageAction(ServerRequestInterface $request): ResponseInterfac
$this->id,
$this->pageinfo,
$this->perms_clause,
$this->returnUrl
$this->returnUrl,
$request
);
$this->view->assign('pagePositionMapForPagesOnly', $content);
// Setting up the buttons and markers for docheader (done after permissions are checked)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace TYPO3\CMS\Backend\Tree\View;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -47,9 +48,19 @@ public function getActionLink($pid, $newPagePID): string
* @param array $rec Page record (?)
* @return string Wrapped title.
*/
public function linkPageTitle($str, $rec)
public function linkPageTitle($str, $rec, ServerRequestInterface $request)
{
$url = GeneralUtility::linkThisScript(['uid' => (int)$rec['uid'], 'moveUid' => $this->moveUid]);
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$queryParams = $request->getQueryParams();
$url = $uriBuilder->buildUriFromRoute(
'move_element',
[
'table' => $queryParams['table'] ?? '',
'uid' => (int)($rec['uid'] ?? 0),
'moveUid' => $this->moveUid,
'returnUrl' => $queryParams['returnUrl'] ?? '',
]
);
return '<a href="' . htmlspecialchars($url) . '">' . $str . '</a>';
}

Expand Down
16 changes: 13 additions & 3 deletions typo3/sysext/backend/Classes/Tree/View/PagePositionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace TYPO3\CMS\Backend\Tree\View;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
Expand Down Expand Up @@ -108,7 +109,7 @@ public function __construct(string $pageTreeClassName = null)
* @param string $R_URI Current REQUEST_URI
* @return string HTML code for the tree.
*/
public function positionTree($id, $pageinfo, $perms_clause, $R_URI)
public function positionTree($id, $pageinfo, $perms_clause, $R_URI, ServerRequestInterface $request)
{
// Make page tree object
if ($this->pageTreeClassName === NewRecordPageTreeView::class) {
Expand Down Expand Up @@ -180,7 +181,16 @@ public function positionTree($id, $pageinfo, $perms_clause, $R_URI)
. $this->iconFactory->getIconForRecord('pages', $dat['row'], Icon::SIZE_SMALL)->render()
. '</span>';

$lines[] = '<span class="text-nowrap">' . $icon . ' ' . $this->linkPageTitle($this->boldTitle(htmlspecialchars(GeneralUtility::fixed_lgd_cs($dat['row']['title'], (int)$this->getBackendUser()->uc['titleLen'])), $dat, $id), $dat['row']) . '</span>';
$lines[] = '<span class="text-nowrap">' . $icon . ' ' .
$this->linkPageTitle(
$this->boldTitle(
htmlspecialchars(GeneralUtility::fixed_lgd_cs($dat['row']['title'], (int)$this->getBackendUser()->uc['titleLen'])),
$dat,
$id
),
$dat['row'],
$request
) . '</span>';
}
// If the current page was the last in the tree:
$prev_dat = end($pageTree->tree);
Expand Down Expand Up @@ -285,7 +295,7 @@ protected function insertlabel()
* @param array $rec Page record (?)
* @return string Wrapped title.
*/
public function linkPageTitle($str, $rec)
public function linkPageTitle($str, $rec, ServerRequestInterface $request)
{
return $str;
}
Expand Down

0 comments on commit 4a36f6d

Please sign in to comment.