From fa7dab55729b268b93f7279767b4da07c7b665c7 Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Sat, 18 Apr 2020 00:32:42 +0200
Subject: [PATCH] [TASK] Make code of EXT:dashboard consistent with other
 system extensions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Made sure EXT:dashboard follows the guidelines for usage of ext_localconf
and ext_tables and some other changed to make the code more consistent
with other system extensions.

Resolves: #91108
Releases: master
Change-Id: I82d957a9e13aee8504b6bf8df6a3145b8fb6a5db
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64221
Tested-by: Christian Eßl <indy.essl@gmail.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Richard Haeser <richard@maxserv.com>
Reviewed-by: Christian Eßl <indy.essl@gmail.com>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Richard Haeser <richard@maxserv.com>
---
 .../Resources/Public/TypeScript/Grid.ts       |  2 +-
 .../TypeScript/WidgetContentCollector.ts      |  2 +-
 .../Configuration/Backend/AjaxRoutes.php      |  8 +++---
 .../Configuration/Backend/Routes.php          |  2 +-
 .../Resources/Public/JavaScript/Grid.js       |  2 +-
 .../JavaScript/WidgetContentCollector.js      |  2 +-
 typo3/sysext/dashboard/ext_localconf.php      | 28 ++++++++-----------
 typo3/sysext/dashboard/ext_tables.php         |  4 ---
 8 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/Grid.ts b/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/Grid.ts
index 353af8a3524b..2aa1f8c647c7 100644
--- a/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/Grid.ts
+++ b/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/Grid.ts
@@ -83,7 +83,7 @@ class Grid {
       ];
     });
 
-    (new AjaxRequest(TYPO3.settings.ajaxUrls['ext-dashboard-save-widget-positions'])).post({
+    (new AjaxRequest(TYPO3.settings.ajaxUrls['dashboard_save_widget_positions'])).post({
       widgets: widgets
     }).then(async (response: AjaxResponse): Promise<any> => {
       await response.resolve();
diff --git a/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/WidgetContentCollector.ts b/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/WidgetContentCollector.ts
index 709327a10c5b..f30c8bc77ff1 100644
--- a/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/WidgetContentCollector.ts
+++ b/Build/Sources/TypeScript/dashboard/Resources/Public/TypeScript/WidgetContentCollector.ts
@@ -29,7 +29,7 @@ class WidgetContentCollector {
       const widgetContentElement = triggerElement.querySelector('.widget-content');
       const widgetErrorElement = triggerElement.querySelector('.widget-error');
 
-      const sentRequest = (new AjaxRequest(TYPO3.settings.ajaxUrls['ext-dashboard-get-widget-content']))
+      const sentRequest = (new AjaxRequest(TYPO3.settings.ajaxUrls['dashboard_get_widget_content']))
         .withQueryArguments({
           widget: triggerElement.dataset.widgetKey,
         })
diff --git a/typo3/sysext/dashboard/Configuration/Backend/AjaxRoutes.php b/typo3/sysext/dashboard/Configuration/Backend/AjaxRoutes.php
index 5e8f44894846..da9445b9928d 100644
--- a/typo3/sysext/dashboard/Configuration/Backend/AjaxRoutes.php
+++ b/typo3/sysext/dashboard/Configuration/Backend/AjaxRoutes.php
@@ -2,13 +2,13 @@
 
 return [
     // Get the content of a widget
-    'ext-dashboard-get-widget-content' => [
-        'path' => '/ext/dashboard/widget/content',
+    'dashboard_get_widget_content' => [
+        'path' => '/dashboard/widget/content',
         'target' => TYPO3\CMS\Dashboard\Controller\WidgetAjaxController::class . '::getContent'
     ],
     // Save positions of the widgets
-    'ext-dashboard-save-widget-positions' => [
-        'path' => '/ext/dashboard/widget/positions/save',
+    'dashboard_save_widget_positions' => [
+        'path' => '/dashboard/widget/positions/save',
         'target' => TYPO3\CMS\Dashboard\Controller\WidgetAjaxController::class . '::savePositions'
     ],
 ];
diff --git a/typo3/sysext/dashboard/Configuration/Backend/Routes.php b/typo3/sysext/dashboard/Configuration/Backend/Routes.php
index 1e597458aebf..39a3aca8379f 100644
--- a/typo3/sysext/dashboard/Configuration/Backend/Routes.php
+++ b/typo3/sysext/dashboard/Configuration/Backend/Routes.php
@@ -2,7 +2,7 @@
 
 return [
     'dashboard' => [
-        'path' => '/ext/dashboard',
+        'path' => '/dashboard',
         'target' => \TYPO3\CMS\Dashboard\Controller\DashboardController::class . '::handleRequest',
     ],
 ];
diff --git a/typo3/sysext/dashboard/Resources/Public/JavaScript/Grid.js b/typo3/sysext/dashboard/Resources/Public/JavaScript/Grid.js
index ad97067b277b..7f6f59588dc2 100644
--- a/typo3/sysext/dashboard/Resources/Public/JavaScript/Grid.js
+++ b/typo3/sysext/dashboard/Resources/Public/JavaScript/Grid.js
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","muuri","TYPO3/CMS/Core/Ajax/AjaxRequest","TYPO3/CMS/Core/Event/RegularEvent"],(function(e,t,a,r,s){"use strict";return new class{constructor(){this.selector=".dashboard-grid",this.initialize()}initialize(){const e={dragEnabled:!0,dragSortHeuristics:{sortInterval:50,minDragDistance:10,minBounceBackAngle:1},layoutDuration:400,layoutEasing:"ease",dragPlaceholder:{enabled:!0,duration:400,createElement:e=>e.getElement().cloneNode(!0)},dragSortPredicate:{action:"move",threshold:30},dragStartPredicate:{handle:".js-dashboard-move-widget"},dragReleaseDuration:400,dragReleaseEasing:"ease",layout:{fillGaps:!1,rounding:!1}};if(null!==document.querySelector(this.selector)){const t=new a(this.selector,e);t.on("dragStart",()=>{document.querySelectorAll(".dashboard-item").forEach(e=>{e.classList.remove("dashboard-item--enableSelect")})}),t.on("dragReleaseEnd",()=>{document.querySelectorAll(".dashboard-item").forEach(e=>{e.classList.add("dashboard-item--enableSelect")}),this.saveItems(t)}),new s("widgetContentRendered",()=>{t.refreshItems().layout()}).delegateTo(document,".dashboard-item")}}saveItems(e){let t=e.getItems().map((function(e){return[e.getElement().getAttribute("data-widget-key"),e.getElement().getAttribute("data-widget-hash")]}));new r(TYPO3.settings.ajaxUrls["ext-dashboard-save-widget-positions"]).post({widgets:t}).then(async e=>{await e.resolve()})}}}));
\ No newline at end of file
+define(["require","exports","muuri","TYPO3/CMS/Core/Ajax/AjaxRequest","TYPO3/CMS/Core/Event/RegularEvent"],(function(e,t,a,r,s){"use strict";return new class{constructor(){this.selector=".dashboard-grid",this.initialize()}initialize(){const e={dragEnabled:!0,dragSortHeuristics:{sortInterval:50,minDragDistance:10,minBounceBackAngle:1},layoutDuration:400,layoutEasing:"ease",dragPlaceholder:{enabled:!0,duration:400,createElement:e=>e.getElement().cloneNode(!0)},dragSortPredicate:{action:"move",threshold:30},dragStartPredicate:{handle:".js-dashboard-move-widget"},dragReleaseDuration:400,dragReleaseEasing:"ease",layout:{fillGaps:!1,rounding:!1}};if(null!==document.querySelector(this.selector)){const t=new a(this.selector,e);t.on("dragStart",()=>{document.querySelectorAll(".dashboard-item").forEach(e=>{e.classList.remove("dashboard-item--enableSelect")})}),t.on("dragReleaseEnd",()=>{document.querySelectorAll(".dashboard-item").forEach(e=>{e.classList.add("dashboard-item--enableSelect")}),this.saveItems(t)}),new s("widgetContentRendered",()=>{t.refreshItems().layout()}).delegateTo(document,".dashboard-item")}}saveItems(e){let t=e.getItems().map((function(e){return[e.getElement().getAttribute("data-widget-key"),e.getElement().getAttribute("data-widget-hash")]}));new r(TYPO3.settings.ajaxUrls["dashboard_save_widget_positions"]).post({widgets:t}).then(async e=>{await e.resolve()})}}}));
diff --git a/typo3/sysext/dashboard/Resources/Public/JavaScript/WidgetContentCollector.js b/typo3/sysext/dashboard/Resources/Public/JavaScript/WidgetContentCollector.js
index 7e3bf0d2d451..edd702aa284e 100644
--- a/typo3/sysext/dashboard/Resources/Public/JavaScript/WidgetContentCollector.js
+++ b/typo3/sysext/dashboard/Resources/Public/JavaScript/WidgetContentCollector.js
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","TYPO3/CMS/Core/Ajax/AjaxRequest"],(function(e,t,n){"use strict";return new class{constructor(){this.selector=".dashboard-item",this.initialize()}initialize(){document.querySelectorAll(this.selector).forEach(e=>{const t=e.querySelector(".widget-waiting"),s=e.querySelector(".widget-content"),i=e.querySelector(".widget-error");new n(TYPO3.settings.ajaxUrls["ext-dashboard-get-widget-content"]).withQueryArguments({widget:e.dataset.widgetKey}).get().then(async n=>{const i=await n.resolve();let r;null!==s&&(s.innerHTML=i.content,s.classList.remove("hide")),null!==t&&t.classList.add("hide");const a={bubbles:!0};r=Object.keys(i.eventdata).length>0?new CustomEvent("widgetContentRendered",Object.assign(Object.assign({},a),{detail:i.eventdata})):new Event("widgetContentRendered",a),e.dispatchEvent(r)}).catch(n=>{null!==i&&i.classList.remove("hide"),null!==t&&t.classList.add("hide"),console.warn(`Error while retrieving widget [${e.dataset.widgetKey}] content: ${n.message}`)})})}}}));
\ No newline at end of file
+define(["require","exports","TYPO3/CMS/Core/Ajax/AjaxRequest"],(function(e,t,n){"use strict";return new class{constructor(){this.selector=".dashboard-item",this.initialize()}initialize(){document.querySelectorAll(this.selector).forEach(e=>{const t=e.querySelector(".widget-waiting"),s=e.querySelector(".widget-content"),i=e.querySelector(".widget-error");new n(TYPO3.settings.ajaxUrls["dashboard_get_widget_content"]).withQueryArguments({widget:e.dataset.widgetKey}).get().then(async n=>{const i=await n.resolve();let r;null!==s&&(s.innerHTML=i.content,s.classList.remove("hide")),null!==t&&t.classList.add("hide");const a={bubbles:!0};r=Object.keys(i.eventdata).length>0?new CustomEvent("widgetContentRendered",Object.assign(Object.assign({},a),{detail:i.eventdata})):new Event("widgetContentRendered",a),e.dispatchEvent(r)}).catch(n=>{null!==i&&i.classList.remove("hide"),null!==t&&t.classList.add("hide"),console.warn(`Error while retrieving widget [${e.dataset.widgetKey}] content: ${n.message}`)})})}}}));
diff --git a/typo3/sysext/dashboard/ext_localconf.php b/typo3/sysext/dashboard/ext_localconf.php
index 402eae82906a..494c64343068 100644
--- a/typo3/sysext/dashboard/ext_localconf.php
+++ b/typo3/sysext/dashboard/ext_localconf.php
@@ -4,21 +4,15 @@ if (!defined('TYPO3_MODE')) {
     die('Access denied.');
 }
 
-call_user_func(static function () {
-    if (TYPO3_MODE === 'BE') {
-        if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard_rss'])) {
-            $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard_rss'] = [
-                'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
-                'backend' => \TYPO3\CMS\Core\Cache\Backend\FileBackend::class,
-                'options' => [
-                    'defaultLifetime' => 900,
-                ],
-            ];
-        }
+if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard_rss'])) {
+    $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['dashboard_rss'] = [
+        'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
+        'backend' => \TYPO3\CMS\Core\Cache\Backend\FileBackend::class,
+        'options' => [
+            'defaultLifetime' => 900,
+        ],
+    ];
+}
 
-        /**
-         * Set starting module to dashboard if users didn't change it
-         */
-        $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUC']['startModule'] = 'dashboard';
-    }
-});
+// Set starting module to dashboard if users didn't change it
+$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultUC']['startModule'] = 'dashboard';
diff --git a/typo3/sysext/dashboard/ext_tables.php b/typo3/sysext/dashboard/ext_tables.php
index 92d5954a6842..417d91d640e0 100644
--- a/typo3/sysext/dashboard/ext_tables.php
+++ b/typo3/sysext/dashboard/ext_tables.php
@@ -2,10 +2,6 @@
 
 defined('TYPO3_MODE') or die();
 
-$GLOBALS['TBE_MODULES']['_configuration']['dashboard'] = [
-    'labels' => 'LLL:EXT:dashboard/Resources/Private/Language/locallang_mod.xlf',
-    'name' => 'dashboard'
-];
 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule(
     'dashboard',
     '',
-- 
GitLab