[TASK] Move flash message handling from DocumentTemplate to own class 00/53200/3
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 13 Jun 2017 12:33:57 +0000 (14:33 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 11 Sep 2017 12:18:40 +0000 (14:18 +0200)
To simplify the class \TYPO3\CMS\Backend\Template\DocumentTemplate, the
AJAX based flash message handling is moved to an own class.

Adding a RST file will be added with other removals within DocumentTemplate.

Resolves: #81564
Releases: master
Change-Id: Icff696f2dc8a2a895711218b86ea529128506161
Reviewed-on: https://review.typo3.org/53200
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Controller/FlashMessageController.php [new file with mode: 0644]
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Configuration/Backend/AjaxRoutes.php

diff --git a/typo3/sysext/backend/Classes/Controller/FlashMessageController.php b/typo3/sysext/backend/Classes/Controller/FlashMessageController.php
new file mode 100644 (file)
index 0000000..d4aaee4
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+declare(strict_types=1);
+namespace TYPO3\CMS\Backend\Controller;
+
+/*
+ * 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!
+ */
+
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Render FlashMessages
+ */
+class FlashMessageController
+{
+    /**
+     * Renders the FlashMessages from queue and returns them as JSON.
+     *
+     * @param ServerRequestInterface $request
+     * @param ResponseInterface $response
+     * @return ResponseInterface
+     */
+    public function getQueuedFlashMessagesAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
+    {
+        $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
+        $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+        $flashMessages = $defaultFlashMessageQueue->getAllMessagesAndFlush();
+
+        $messages = [];
+        foreach ($flashMessages as $flashMessage) {
+            $messages[] = [
+                'title' => $flashMessage->getTitle(),
+                'message' => $flashMessage->getMessage(),
+                'severity' => $flashMessage->getSeverity()
+            ];
+        }
+
+        $response->getBody()->write(json_encode($messages));
+        return $response;
+    }
+}
index 446bf20..3ae2f66 100644 (file)
@@ -14,8 +14,6 @@ namespace TYPO3\CMS\Backend\Template;
  * The TYPO3 project - inspiring people to share!
  */
 
-use Psr\Http\Message\ResponseInterface;
-use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
@@ -835,34 +833,6 @@ function jumpToUrl(URL) {
     }
 
     /**
-     * Renders the FlashMessages from queue and returns them as AJAX.
-     *
-     * @param ServerRequestInterface $request
-     * @param ResponseInterface $response
-     * @return ResponseInterface
-     */
-    public function renderQueuedFlashMessages(ServerRequestInterface $request, ResponseInterface $response)
-    {
-        /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
-        $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
-        /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
-        $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
-        $flashMessages = $defaultFlashMessageQueue->getAllMessagesAndFlush();
-
-        $messages = [];
-        foreach ($flashMessages as $flashMessage) {
-            $messages[] = [
-                'title' => $flashMessage->getTitle(),
-                'message' => $flashMessage->getMessage(),
-                'severity' => $flashMessage->getSeverity()
-            ];
-        }
-
-        $response->getBody()->write(json_encode($messages));
-        return $response;
-    }
-
-    /**
      * Fill the button lists with the defined HTML
      *
      * @param array $buttons HTML for all buttons
index ef9c745..976f0b7 100644 (file)
@@ -165,7 +165,7 @@ return [
     // Render flash messages
     'flashmessages_render' => [
         'path' => '/flashmessages/render',
-        'target' => \TYPO3\CMS\Backend\Template\DocumentTemplate::class . '::renderQueuedFlashMessages'
+        'target' => \TYPO3\CMS\Backend\Controller\FlashMessageController::class . '::getQueuedFlashMessagesAction'
     ],
 
     // Load context menu for