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

[TASK] Deprecate inline JavaScript in Dashboard

Using inline JavaScript when initializing RequireJS modules in
individual dashboard widgets has been deprecated. Widget
implementations have to be adjusted accordingly.

Basically `RequireJsModuleInterface` has to be replaced by
`JavaScriptInterface` relying on `JavaScriptModuleInstruction`.

Resolves: #96524
Releases: main
Change-Id: I5eb74aa54aef6d4f3a9419aaa7e2d391d98ce408
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73002

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent bb927efe
.. include:: ../../Includes.txt
==============================================================
Deprecation: #96524 - Deprecate inline JavaScript in Dashboard
==============================================================
See :issue:`96524`
Description
===========
Using inline JavaScript when initializing RequireJS modules in individual
dashboard widgets has been deprecated. Widget implementations have to be
adjusted accordingly.
Impact
======
Deprecation errors will be logged.
Affected Installations
======================
Installations having individual widget implementations which are
* implementing :php:`\TYPO3\CMS\Dashboard\Widgets\RequireJsModuleInterface`
* invoking :php:`\TYPO3\CMS\Dashboard\DashboardInitializationService->getRequireJsModules`
Migration
=========
Affected widget have to implement :php:`\TYPO3\CMS\Dashboard\Widgets\JavaScriptInterface`
instead of deprecated :php:`\TYPO3\CMS\Dashboard\Widgets\RequireJsModuleInterface`.
Instead of using inline JavaScript for initializing RequireJS modules,
:php:`\TYPO3\CMS\Core\Page\JavaScriptModuleInstruction` have to be declared.
.. code-block:: php
class ExampleChartWidget implements RequireJsModuleInterface
{
// ...
public function getJavaScriptModuleInstructions(): array
{
return [
'TYPO3/CMS/Dashboard/ChartInitializer' =>
'function(ChartInitializer) { ChartInitializer.initialize(); }',
];
}
}
Deprecated example widget above would look like the following when using
`JavaScriptInterface` and `JavaScriptModuleInstruction`:
.. code-block:: php
class ExampleChartWidget implements JavaScriptInterface
{
// ...
public function getJavaScriptModuleInstructions(): array
{
return [
JavaScriptModuleInstruction::forRequireJS(
'TYPO3/CMS/Dashboard/ChartInitializer'
)->invoke('initialize'),
];
}
}
.. index:: Frontend, TypoScript, FullyScanned, ext:core
......@@ -249,7 +249,6 @@ class DashboardController extends AbstractController
foreach ($this->dashboardInitializationService->getJavaScriptModuleInstructions() as $instruction) {
$javaScriptRenderer->addJavaScriptModuleInstruction($instruction);
}
// @todo Deprecate `RequireJsModuleInterface` in TYPO3 v12.0
foreach ($this->dashboardInitializationService->getRequireJsModules() as $requireJsModule) {
if (is_array($requireJsModule)) {
$this->pageRenderer->loadRequireJsModule($requireJsModule[0], $requireJsModule[1]);
......
......@@ -25,6 +25,7 @@ use TYPO3\CMS\Dashboard\Widgets\AdditionalCssInterface;
use TYPO3\CMS\Dashboard\Widgets\AdditionalJavaScriptInterface;
use TYPO3\CMS\Dashboard\Widgets\JavaScriptInterface;
use TYPO3\CMS\Dashboard\Widgets\RequireJsModuleInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface;
/**
* @internal
......@@ -60,6 +61,7 @@ class DashboardInitializationService
/**
* @var list<string|list<string>>
* @deprecated will be removed in TYPO3 v13.0
*/
private $requireJsModules = [];
private $jsFiles = [];
......@@ -144,7 +146,7 @@ class DashboardInitializationService
}
/**
* @param array $widgets
* @param array<string,WidgetConfigurationInterface> $widgets
*/
protected function defineResourcesOfWidgets(array $widgets): void
{
......@@ -154,6 +156,7 @@ class DashboardInitializationService
$this->defineJavaScriptInstructions($concreteInstance);
}
if ($concreteInstance instanceof RequireJsModuleInterface) {
trigger_error('Using RequireJsModuleInterface is deprecated and will be removed in TYPO3 v13.0.', E_USER_DEPRECATED);
$this->defineRequireJsModules($concreteInstance);
}
if ($concreteInstance instanceof AdditionalCssInterface) {
......@@ -176,6 +179,7 @@ class DashboardInitializationService
* Add the RequireJS modules needed by some widgets
*
* @param RequireJsModuleInterface $widgetInstance
* @deprecated will be removed in TYPO3 v13.0
*/
protected function defineRequireJsModules(RequireJsModuleInterface $widgetInstance): void
{
......@@ -240,10 +244,11 @@ class DashboardInitializationService
/**
* @return list<string|list<string>>
* @internal Deprecate in TYPO3 v12.0
* @deprecated will be removed in TYPO3 v13.0
*/
public function getRequireJsModules(): array
{
trigger_error('DashboardInitializationService::getRequireJsModules is deprecated and will be removed in TYPO3 v13.0', E_USER_DEPRECATED);
return $this->requireJsModules;
}
......
......@@ -19,8 +19,7 @@ namespace TYPO3\CMS\Dashboard\Widgets;
/**
* In case a widget should provide additional requireJS modules, the widget must implement this interface.
* @todo deprecate in TYPO3 v12.0
* @internal migrate to JavaScriptInstructionInterface in TYPO3 v12.0
* @deprecated will be removed in TYPO3 v13.0, migrate to JavaScriptInterface instead
*/
interface RequireJsModuleInterface
{
......
......@@ -1553,6 +1553,11 @@ return [
'Breaking-91066-MovedInterfacesOfDashboard.rst',
],
],
'\TYPO3\CMS\Dashboard\Widgets\RequireJsModuleInterface' => [
'restFiles' => [
'Deprecation-96524-DeprecateInlineJavaScriptInDashboard.rst',
],
],
'TYPO3\CMS\Dashboard\Utility\ButtonUtility' => [
'restFiles' => [
'Breaking-91066-RemovedButtonUtility.rst',
......
......@@ -550,6 +550,13 @@ return [
'Deprecation-74156-TemplateServicesortedKeyListAndTemplateService-removeQueryString.rst',
],
],
'\TYPO3\CMS\Dashboard\DashboardInitializationService->getRequireJsModules' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-96524-DeprecateInlineJavaScriptInDashboard.rst',
],
],
'TYPO3\CMS\Extbase\Persistence\Generic\Qom\Comparison->getParameterIdentifier' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
......
Markdown is supported
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