Commit 4e12b62f authored by Oliver Hader's avatar Oliver Hader Committed by Benni Mack
Browse files

[TASK] Remove goToModule() inline JavaScript invocations

This change reduces the amount of inline JavaScript and transforms
`goToModule()` invocations in the TYPO3 backend user interface to use
`ActionDispatcher`'s `TYPO3.ModuleMenu.showModule` handling.

Resolves: #94058
Releases: master
Change-Id: I0411100ae6ec9c5d9493c00fb4efd80b4858ee0e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69015

Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent c38fc440
......@@ -375,10 +375,6 @@ class BackendController
navFrameHighlightedID: [], // used by navigation frames to track which row id was highlighted last time
currentBank: "0"
};
var goToModule = function(modName, addGetVars) {
TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
}
' . $this->handlePageEditing($request),
false
);
......
......@@ -358,7 +358,8 @@ class PageLayoutController
if (is_array($modules['web']['sub']['list'])) {
$title = $lang->getLL('goToListModule');
$message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
$message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\');">' . $lang->getLL('goToListModule') . '</a>';
$message .= '<a class="btn btn-info" data-dispatch-action="TYPO3.ModuleMenu.showModule" data-dispatch-args-list="web_list">'
. $lang->getLL('goToListModule') . '</a>';
$view->assignMultiple([
'title' => $title,
'message' => $message,
......
......@@ -301,9 +301,11 @@ class BackendModule
* Set onClick
*
* @param string $onClick
* @deprecated using inline JavaScript is deprecated, will be removed in TYPO3 v12.0
*/
public function setOnClick($onClick)
{
trigger_error('BackendModule::setOnClick() is deprecated and will be removed in v12.', E_USER_DEPRECATED);
$this->onClick = $onClick;
}
......@@ -311,9 +313,11 @@ class BackendModule
* Get onClick
*
* @return string
* @deprecated using inline JavaScript is deprecated, will be removed in TYPO3 v12.0
*/
public function getOnClick()
{
trigger_error('BackendModule::getOnClick() is deprecated and will be removed in v12.', E_USER_DEPRECATED);
return $this->onClick;
}
......
......@@ -260,7 +260,6 @@ class BackendModuleRepository implements SingletonInterface
$modules[$moduleKey] = [
'name' => $moduleName,
'title' => $moduleLabels['title'],
'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName) . ');',
'icon' => $this->getModuleIcon($moduleKey, $moduleData),
'link' => $moduleLink,
'component' => $moduleComponent,
......@@ -272,7 +271,6 @@ class BackendModuleRepository implements SingletonInterface
$modules[$moduleKey]['subitems'][$moduleKey] = [
'name' => $moduleName,
'title' => $moduleLabels['title'],
'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName) . ');',
'icon' => $this->getModuleIcon($moduleKey, $moduleData),
'link' => $moduleLink,
'component' => $moduleComponent,
......@@ -298,7 +296,6 @@ class BackendModuleRepository implements SingletonInterface
$modules[$moduleKey]['subitems'][$submoduleKey] = [
'name' => $moduleName . '_' . $submoduleName,
'title' => $submoduleLabels['title'],
'onclick' => 'top.goToModule(' . GeneralUtility::quoteJSvalue($moduleName . '_' . $submoduleName) . ');',
'icon' => $this->getModuleIcon($moduleKey, $submoduleData),
'link' => $submoduleLink,
'component' => $submoduleComponent,
......
......@@ -10,7 +10,8 @@
<f:for each="{mainModule.subModules}" as="subModule" iteration="subModuleIterator">
<a
href="#"
onclick="top.goToModule('{mainModule.name}_{subModule.name}'); return false;"
data-dispatch-action="TYPO3.ModuleMenu.showModule"
data-dispatch-args-list="{mainModule.name}_{subModule.name}"
title="{f:if(condition: subModule.shortDescription, then: '{f:translate(key: subModule.shortDescription)}')}"
class="card card-size-medium"
>
......
......@@ -71,3 +71,13 @@ function getModuleUrl(inUrl) { //
// Used by Frameset Modules
var currentSubScript = "";
/**
* @param {string} modName
* @param {string} addGetVars
* @deprecated use `data-dispatch-action=TYPO3.ModuleMenu.showModule` instead, will be removed in TYPO3 v12.0
*/
function goToModule(modName, addGetVars) {
console.warn('Using goToModule is deprecated, use `data-dispatch-action=TYPO3.ModuleMenu.showModule` instead.');
TYPO3.ModuleMenu.App.showModule(modName, addGetVars);
}
.. include:: ../../Includes.txt
=============================================
Deprecation: #94058 - JavaScript goToModule()
=============================================
See :issue:`94058`
Description
===========
One of the most prominent inline JavaScript functions :javascript:`goToModule()` has been deprecated in favor of
a streamlined ActionHandler API for JavaScript.
Impact
======
When using the internal Backend Module entry objects via `setOnClick` and `getOnClick` methods, PHP deprecation warnings are now triggered.
Affected Installations
======================
TYPO3 installations with custom extensions referencing these methods.
Migration
=========
Use the following HTML code to replace the inline `goToModule()`
call to e.g. link to the page module:
:html:`<a href="#" data-dispatch-action="TYPO3.ModuleMenu.showModule" data-dispatch-args-list="web_layout">Go to page module</a>`
.. index:: JavaScript, FullyScanned, ext:backend
\ No newline at end of file
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Dashboard\ViewHelpers\Widget;
use TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface;
use TYPO3\CMS\Dashboard\Widgets\ElementAttributesInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* @internal
*
* Renders a dashboard button
*
* Examples
* ========
*
* ::
*
* <dashboard:widget.button button="{button}" class="widget-cta">
* {f:translate(id: button.title, default: button.title)}
* </dashboard:widget.button button="{button}" class="widget-cta">
*/
class ButtonViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument('button', ButtonProviderInterface::class, 'Dashboard widget button', true);
}
public function render(): string
{
$button = $this->arguments['button'];
$this->tag->addAttribute('href', $button->getLink() ?: '#');
$target = $button->getTarget();
if ($target !== '') {
$this->tag->addAttribute('target', $target);
if ($target === '_blank') {
$this->tag->addAttribute('rel', 'noreferrer');
}
}
if ($button instanceof ElementAttributesInterface) {
$this->tag->addAttributes($button->getElementAttributes());
}
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Dashboard\Widgets;
/**
* In case HTML element shall contain additional attributes
*/
interface ElementAttributesInterface
{
/**
* @return array<string, string|null>
*/
public function getElementAttributes(): array;
}
......@@ -18,15 +18,15 @@ declare(strict_types=1);
namespace TYPO3\CMS\Dashboard\Widgets\Provider;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface;
use TYPO3\CMS\Dashboard\Widgets\ElementAttributesInterface;
/**
* Provide link for sys log button.
* Check whether belog is enabled and add link to module.
* No link is returned if not enabled.
*/
class SysLogButtonProvider implements ButtonProviderInterface
class SysLogButtonProvider implements ButtonProviderInterface, ElementAttributesInterface
{
/**
* @var string
......@@ -51,12 +51,6 @@ class SysLogButtonProvider implements ButtonProviderInterface
public function getLink(): string
{
if (ExtensionManagementUtility::isLoaded('belog')) {
return 'javascript:top.goToModule('
. GeneralUtility::quoteJSvalue('system_BelogLog') . ', '
. GeneralUtility::quoteJSvalue('&' . http_build_query(['tx_belog_system_beloglog' => ['constraint' => ['action' => -1]]])) . ');';
}
return '';
}
......@@ -64,4 +58,16 @@ class SysLogButtonProvider implements ButtonProviderInterface
{
return $this->target;
}
public function getElementAttributes(): array
{
if (!ExtensionManagementUtility::isLoaded('belog')) {
return [];
}
return [
'data-dispatch-action' => 'TYPO3.ModuleMenu.showModule',
'data-dispatch-args-list' => 'system_BelogLog,&'
. http_build_query(['tx_belog_system_beloglog' => ['constraint' => ['action' => -1]]]),
];
}
}
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:dashboard="http://typo3.org/ns/TYPO3/CMS/Dashboard/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:if condition="{button}">
<a href="{button.link}" class="widget-cta"{f:if(condition: '{button.target}', then: ' target="{button.target}"')}{f:if(condition: '{button.target} == "_blank"', then: ' rel="noreferrer"')}>{f:translate(id: button.title, default: button.title)}</a>
<dashboard:widget.button button="{button}" class="widget-cta">{f:translate(id: button.title, default: button.title)}</dashboard:widget.button>
</f:if>
</html>
......@@ -23,12 +23,16 @@
</f:else>
<f:then>
<li>
<button class="btn btn-default distribution-openViewModule" onclick="top.goToModule('web_ViewpageView');">
<button class="btn btn-default distribution-openViewModule"
data-dispatch-action="TYPO3.ModuleMenu.showModule"
data-dispatch-args-list="web_ViewpageView">
<core:icon identifier="actions-document-view" /> <f:translate key="distribution.welcome.openViewModule" />
</button>
</li>
<li>
<button class="btn btn-default distribution-openPageModule" onclick="top.goToModule('web_layout');">
<button class="btn btn-default distribution-openPageModule"
data-dispatch-action="TYPO3.ModuleMenu.showModule"
data-dispatch-args-list="web_layout">
<core:icon identifier="actions-open" /> <f:translate key="distribution.welcome.openPageModule" />
</button>
</li>
......
......@@ -4795,4 +4795,18 @@ return [
'Deprecation-93837-SpecialPropertyOfTCATypeSelect.rst'
],
],
'TYPO3\CMS\Backend\Domain\Model\Module\BackendModule->setOnClick' => [
'numberOfMandatoryArguments' => 1,
'maximumNumberOfArguments' => 1,
'restFiles' => [
'Deprecation-94058-JavaScriptGoToModule.rst'
],
],
'TYPO3\CMS\Backend\Domain\Model\Module\BackendModule->getOnClick' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-94058-JavaScriptGoToModule.rst'
],
],
];
......@@ -55,9 +55,11 @@ class WarningMessagePostProcessor
'tx_reports_system_reportstxreportsm1[action]=detail',
'tx_reports_system_reportstxreportsm1[controller]=Report',
];
$dispatchArgsList = $reportModuleIdentifier . ',' . '&' . implode('&', $reportModuleParameters);
$warningMessages['tx_reports_status_notification'] = sprintf(
$this->getLanguageService()->getLL('status_problemNotification'),
'<a href="javascript:top.goToModule(' . GeneralUtility::quoteJSvalue($reportModuleIdentifier) . ', ' . GeneralUtility::quoteJSvalue('&' . implode('&', $reportModuleParameters)) . ');">',
'<a href="#" data-dispatch-action="TYPO3.ModuleMenu.showModule" '
. 'data-dispatch-args-list="' . htmlspecialchars($dispatchArgsList) . '">',
'</a>'
);
}
......
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