trash-panda / m2-message-manager-remover
Remove messages from the message manager
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Type:magento2-module
Requires
- php: ^7.2
- magento/framework: ^101.0|^102.0
Requires (Dev)
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2024-11-27 07:56:35 UTC
README
A small utility to remove messages added to the message manager
Installation
$ composer require trash-panda/m2-message-manager-remover $ php bin/magento setup:upgrade
Usage
Inject \TrashPanda\MessageManagerRemover\Remover
wherever you need to remove a message. The class has two public
methods for removing messages.
removeLastAddedMessage
will remove the last added message or throw a \RuntimeException if one does not exist
removeByRegex
will remove all message matching a given preg_match
compatible regex. It will return the number of messages removed
'removeAll' will remove all messages from the message manager
Examples
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $messageManager = $om->create(\Magento\Framework\Message\ManagerInterface::class); $messageManager->addNotice('First message'); $messageManager->addNotice('Second message'); $remover = new Remover($messageManager); $remover->removeLastAddedMessage(); //only remove "Second Message" $remover->removeByRegex('/message/'); //remove all message matching regex '/message/' $remover->removeAll(); //remove all messages