Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aydinhassan/m2-message-manager-remover
A small utility to remove messages added to the message manager
https://github.com/aydinhassan/m2-message-manager-remover
magento2 magento2-module
Last synced: 1 day ago
JSON representation
A small utility to remove messages added to the message manager
- Host: GitHub
- URL: https://github.com/aydinhassan/m2-message-manager-remover
- Owner: AydinHassan
- Created: 2019-12-26T19:28:51.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-26T21:02:03.000Z (almost 5 years ago)
- Last Synced: 2024-04-17T11:18:04.613Z (6 months ago)
- Topics: magento2, magento2-module
- Language: PHP
- Size: 25.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Magento 2 Message Manager Remover
A small utility to remove messages added to the message manager
## Installation
```sh
$ 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
```php
$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```