trash-panda/m2-message-manager-remover

Remove messages from the message manager

1.0.0 2019-12-26 20:49 UTC

This package is auto-updated.

Last update: 2024-04-27 06:51:55 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f417964696e48617373616e2f6d322d6d6573736167652d6d616e616765722d72656d6f7665722f6d61737465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d4c696e7578

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