addFlashMessage from a service

Good Morning Guys,

in my Neos Site I have a Service connected to the signal TYPO3\TYPO3CR\Domain\Model\Workspace->afterNodePublishing.
In some cases, I want to notify the user of a action the service did. Obviously, as I’m not directly in the controller, I can’t call $this->addFlashMessage() as I would normally do. So is there a way to add a flash message from outside the controller?

Many tanks in advance!


just use the source and have a look what addFlashMessage() does internally.

It should be possible to do the same thing:

use TYPO3\Flow\Error\Notice;
use TYPO3\Flow\Mvc\FlashMessageContainer;

class YourService {

     * @Flow\Inject
     * @var FlashMessageContainer
    protected $flashMessageContainer;

    public function someMethod() {
            $this->flashMessageContainer->addMessage(new Notice('<message body>', '<message code>', ['message', 'arguments'], '>message title>'));
1 Like

Hi Bastian,

works perfectly. Sometimes things are so easy if you look at the right spots :wink:

Thank you :smile: