[BUGFIX] Flash messages are not shown with AJAX requests 52/44652/2
authorXavier Perseguers <xavier@typo3.org>
Tue, 10 Nov 2015 09:33:11 +0000 (10:33 +0100)
committerFrank Nägler <frank.naegler@typo3.org>
Tue, 10 Nov 2015 11:09:43 +0000 (12:09 +0100)
Direct DOM manipulation is avoided in favour of using the
top.Notification object to trigger TYPO3 7 native notifications.

Resolves: #71453
Related: #56561
Releases: master
Change-Id: I8c39d8100153b106e89ee1e7259ff1a0cc7ad572
Reviewed-on: https://review.typo3.org/44652
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js

index b96fb8e..2bbc1a6 100644 (file)
@@ -1789,7 +1789,22 @@ function jumpToUrl(URL) {
      */
     public function renderQueuedFlashMessages(ServerRequestInterface $request, ResponseInterface $response)
     {
-        $response->getBody()->write($this->getFlashMessages());
+        /** @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;
     }
 
index f566ebe..e0b9b1b 100644 (file)
@@ -277,12 +277,9 @@ define(['jquery', 'moment', 'nprogress', 'TYPO3/CMS/Backend/Modal', 'TYPO3/CMS/L
                                                url: TYPO3.settings.ajaxUrls['flashmessages_render'],
                                                cache: false,
                                                success: function(data) {
-                                                       var messages = $('#typo3-messages');
-                                                       if (messages.length == 0) {
-                                                               $('#typo3-inner-docbody').prepend(data);
-                                                       } else {
-                                                               messages.replaceWith(data);
-                                                       }
+                                                       $.each(data, function(index, flashMessage) {
+                                                               top.TYPO3.Notification.showMessage(flashMessage.title, flashMessage.message, flashMessage.severity);
+                                                       });
                                                }
                                        });
                                }