typo3flash-message

How do I show flash messages from a different extension/plugin?


In Typo3 7.x, I need to show a flashmessage after a redirect to a different extension. Somehow, the messages are not shown there:

// in powermail_extended:

$this->addFlashMessage('Some message', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::NOTICE);

$uri = $this->uriBuilder->uriFor('form', [], 'Form', 'powermail', 'pi1');
$this->redirectToURI($uri);

Are the flash messages only shown if the same frontend plugin will be shown after the redirect? If so, how can I show the "foreign" flash messages as well?


Solution

  • Yes, the flash messages are in different queues depending on the frontend plugin. In the Controller after the redirect, add the following lines:

    protected function emitBeforeCallActionMethodSignal(array $preparedArguments) {
        parent::emitBeforeCallActionMethodSignal($preparedArguments);
        $this->addMessagesToDefaultQueue('extbase.flashmessages.tx_powermailextended_pi1' /* depending on your frontend plugin name */);
    }
    
    protected function addMessagesToDefaultQueue($queueId) {
        $queue = $this->controllerContext->getFlashMessageQueue($queueId); 
        $msg = $queue->getAllMessagesAndFlush();
        if ($msg) {
            $defaultQueue = $this->controllerContext->getFlashMessageQueue();
            foreach ($msg as $m) {
                $defaultQueue->enqueue($m);
            }
        }
    }
    

    This will remove the messages from the plugin before the redirect and add it to "correct" queue.