2

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?

giraff
  • 4,601
  • 2
  • 23
  • 35

2 Answers2

4

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.

giraff
  • 4,601
  • 2
  • 23
  • 35
1

The reason behind not showing a message to another plugin is queueIdentifier

When you redirect to another plugin then <f:flashMessages /> tries to find your current flashMessage queue which would absolutely empty.

I have found a simple way to show flashMessage to another plugin.

TYPO3 version 10.4x

eg. plugin powermail_extended controller/action

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

   $uriBuilder = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
   $uri = $uriBuilder
          ->reset()
          ->setTargetPageUid($GLOBALS['TSEF']->page['uid'])
          ->uriFor('form', [], 'Form', 'powermail', 'pi1');
   $this->redirectToURI($uri);
}

Another plugin powermail where you need to show flashMessage.

All you need to change code in your view eg. plugin powermail ExtendedView/Resources/Private/Templates/Form/Form.html

<f:flashMessages /> // this will show your default current plugin flashMessage

<f:flashMessages queueIdentifier="extbase.flashmessages.tx_powermailextended_pi1" /> // This will show your flashMessage from another plugin eg. powermail_extended

greetings!

Ghanshyam Gohel
  • 1,264
  • 1
  • 17
  • 27