Commit 81660b4c authored by Andreas Fernandez's avatar Andreas Fernandez Committed by Georg Ringer
Browse files

[TASK] Deprecate T3_THIS_LOCATION

This patch deprecates the global variable `T3_THIS_LOCATION`. This
variable is mostly used to attach a returnUrl argument to links,
triggered via a redirect on an onclick event.

In most cases this is not necessary anymore, also it's considered bad
practice not to use regular links in an href attribute.

Resolves: #88854
Releases: master
Change-Id: I9d90a59b83b956f0bf1e380a55d6c3a4c2d469b5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61385

Tested-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Nägler's avatarFrank Naegler <frank.naegler@typo3.org>
Reviewed-by: Björn Jacob's avatarBjörn Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 33428b6d
......@@ -364,6 +364,7 @@ function jumpToUrl(URL) {
$out = '
// @deprecated
var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
// @deprecated
var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
';
return $out;
......
......@@ -651,6 +651,7 @@ class ModuleTemplate
$out = '
// @deprecated
var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
// @deprecated
var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
';
return $out;
......
......@@ -2484,6 +2484,7 @@ class BackendUtility
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('tce_db') . $parameters . '&redirect=';
if ((int)$redirectUrl === -1) {
trigger_error('Generating URLs to DataHandler for JavaScript click handlers is deprecated. Consider using the href attribute instead.', E_USER_DEPRECATED);
$url = GeneralUtility::quoteJSvalue($url) . '+T3_THIS_LOCATION';
} else {
$url .= rawurlencode($redirectUrl ?: GeneralUtility::getIndpEnv('REQUEST_URI'));
......
.. include:: ../../Includes.txt
=======================================================
Deprecation: #88854 - jumpExt() of RecordListController
=======================================================
See :issue:`88854`
Description
===========
The JavaScript function :js:`jumpExt()` used to generate URLs by attaching a returnUrl argument and an anchor has been
marked as deprecated.
Impact
======
Calling :js:`jumpExt()` will trigger a deprecation warning in the browser's console.
Affected Installations
======================
All third party extensions using :js:`jumpExt()` are affected.
Migration
=========
It is only possible to call this function via hooks. To migrate this call, append a `returnUrl` argument to the URL if
required and move the URL to the :html:`href` argument of the button the function was attached to.
.. index:: Backend, JavaScript, PHP-API, NotScanned, ext:backend
.. include:: ../../Includes.txt
======================================
Deprecation: #88854 - T3_THIS_LOCATION
======================================
See :issue:`88854`
Description
===========
The global JavaScript variable :js:`T3_THIS_LOCATION` containing the URL to the current document (if not modified) has
been marked as deprecated.
Impact
======
Since this is a global JavaScript variable, no proper deprecation layer applies and thus no deprecation notice is rendered.
Some PHP API uses :js:`T3_THIS_LOCATION` (e.g. :php:`BackendUtility::getLinkToDataHandlerAction()` with second argument
being `-1`) has been marked as deprecated as well.
Affected Installations
======================
All third party extensions using :js:`T3_THIS_LOCATION` are affected.
Migration
=========
When generating URLs containing a `returnUrl` (a common use-case for :js:`T3_THIS_LOCATION`), consider using either
:php:`rawurldecode(GeneralUtility::getIndpEnv('REQUEST_URI'))` or :php:`normalizedParams` in the PSR-7 ServerRequest object:
:php:`$request->getAttribute('normalizedParams')->getRequestUri()`.
In general, `onclick` handlers doing a redirect are considered bad practice. Use HTML's `href` attribute and attach
custom click handlers, if necessary.
.. index:: Backend, JavaScript, PHP-API, NotScanned, ext:backend
......@@ -147,7 +147,7 @@ class TableListViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBacken
$dblist->script = $_SERVER['REQUEST_URI'];
$dblist->generateList();
$js = 'var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
$js = '// @deprecated' . CRLF . 'var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
$html = GeneralUtility::wrapJS($js) . $dblist->HTMLcode;
return $html;
......
......@@ -372,6 +372,7 @@ class RecordListController
'RecordListInlineJS',
'
function jumpExt(URL,anchor) {
console.warn(\'jumpExt() has been marked as deprecated. Consider using regular links instead.\');
var anc = anchor?anchor:"";
window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
return false;
......
......@@ -634,10 +634,8 @@ class DatabaseRecordList
}
// New record on pages that are not locked by editlock
if (!$modulePageTsConfig['noCreateRecordsLink'] && $this->editLockPermissions()) {
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id])) . ');';
$newRecordButton = $buttonBar->makeLinkButton()
->setHref('#')
->setOnClick($onClick)
->setHref((string)$this->uriBuilder->buildUriFromRoute('db_new', ['id' => $this->id, 'returnUrl' => $this->listURL()]))
->setTitle($lang->getLL('newRecordGeneral'))
->setIcon($this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
$buttonBar->addButton($newRecordButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
......@@ -1472,7 +1470,7 @@ class DatabaseRecordList
// The "edit marked" link:
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{entityIdentifiers:editList}]=edit'
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$cells['edit'] = '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
. ' title="' . htmlspecialchars($lang->getLL('clip_editMarked')) . '">'
......@@ -1562,7 +1560,7 @@ class DatabaseRecordList
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
. '&columnsOnly=' . implode(',', $this->fieldArray)
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$icon .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
. ' title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">'
......@@ -1620,7 +1618,7 @@ class DatabaseRecordList
$editUri = (string)$this->uriBuilder->buildUriFromRoute('record_edit')
. '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
. '&columnsOnly=' . $fCol
. '&returnUrl={T3_THIS_LOCATION}';
. '&returnUrl=' . rawurlencode($this->listURL());
$iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
$theData[$fCol] .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
. ' data-uri="' . htmlspecialchars($editUri) . '"'
......@@ -1854,10 +1852,14 @@ class DatabaseRecordList
if ($isL10nOverlay) {
$moveAction = $this->spaceIcon;
} else {
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue((string)$this->uriBuilder->buildUriFromRoute('move_element') . '&table=' . $table . '&uid=' . $row['uid']) . ');';
$linkTitleLL = htmlspecialchars($this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page')));
$icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
$moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
$url = (string)$this->uriBuilder->buildUriFromRoute('move_element', [
'table' => $table,
'uid' => $row['uid'],
'returnUrl' => $this->listURL(),
]);
$moveAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
}
$this->addActionToCellGroup($cells, $moveAction, 'move');
}
......@@ -1865,9 +1867,11 @@ class DatabaseRecordList
if ($this->isEditable($table)) {
// "Revert" link (history/undo)
if ((bool)\trim($userTsConfig['options.']['showHistory.'][$table] ?? $userTsConfig['options.']['showHistory'] ?? '1')) {
$moduleUrl = (string)$this->uriBuilder->buildUriFromRoute('record_history', ['element' => $table . ':' . $row['uid']]);
$onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
$historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
$moduleUrl = $this->uriBuilder->buildUriFromRoute('record_history', [
'element' => $table . ':' . $row['uid'],
'returnUrl' => $this->listURL(),
]) . '#latest';
$historyAction = '<a class="btn btn-default" href="' . htmlspecialchars($moduleUrl) . '" title="'
. htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
. $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
$this->addActionToCellGroup($cells, $historyAction, 'history');
......@@ -1909,9 +1913,8 @@ class DatabaseRecordList
if (!$isL10nOverlay && isset($this->currentTable['prev'][$row['uid']])) {
// Up
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
$moveUpAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveUpAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
. $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveUpAction = $this->spaceIcon;
......@@ -1921,9 +1924,8 @@ class DatabaseRecordList
if (!$isL10nOverlay && $this->currentTable['next'][$row['uid']]) {
// Down
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
$moveDownAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveDownAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
. $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveDownAction = $this->spaceIcon;
......@@ -2007,9 +2009,8 @@ class DatabaseRecordList
// Up (Paste as the page right after the current parent page)
if ($this->calcPerms & Permission::PAGE_NEW) {
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
$moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveLeftAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
. $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
$this->addActionToCellGroup($cells, $isL10nOverlay ? $this->spaceIcon : $moveLeftAction, 'moveLeft');
}
......@@ -2018,9 +2019,8 @@ class DatabaseRecordList
$localCalcPerms = $backendUser->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
if ($localCalcPerms & Permission::PAGE_NEW) {
$params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
$moveRightAction = '<a class="btn btn-default" href="#" onclick="'
. htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
. '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
$url = BackendUtility::getLinkToDataHandlerAction($params, $this->listURL());
$moveRightAction = '<a class="btn btn-default" href="' . htmlspecialchars($url) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
. $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
} else {
$moveRightAction = $this->spaceIcon;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment