https://github.com/markshust/magento2-module-messages
The Messages module allows you to send success, notice, warning and error messages with HTML.
https://github.com/markshust/magento2-module-messages
Last synced: 5 months ago
JSON representation
The Messages module allows you to send success, notice, warning and error messages with HTML.
- Host: GitHub
- URL: https://github.com/markshust/magento2-module-messages
- Owner: markshust
- License: mit
- Created: 2018-11-06T20:19:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-13T07:44:35.000Z (almost 6 years ago)
- Last Synced: 2025-04-11T13:48:37.038Z (about 1 year ago)
- Language: PHP
- Homepage:
- Size: 79.1 KB
- Stars: 57
- Watchers: 4
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
MarkShust_Messages
## Table of contents
- [Summary](#summary)
- [Installation](#installation)
- [API](#api)
- [Usage](#usage)
- [License](#license)
## Summary
By default, when you call `$this->messageManager->addSuccessMessage` within Magento, you cannot pass custom HTML into your message. This doesn't provide you with the flexibility to provide customized messages to your visitors.
This module provides the ability to display custom messages including HTML, and still escapes the HTML to prevent cross-site scripting (XSS) attacks.
## Installation
```
composer require markshust/magento2-module-messages
bin/magento module:enable MarkShust_Messages
bin/magento setup:upgrade
```
## API
```php
/**
* Any of the built-in complex message functions can be called with this identifer:
* addComplexSuccessMessage
* addComplexNoticeMessage
* addComplexWarningMessage
* addComplexErrorMessage
*
* @param string $identifer Set to 'withHtml' to use this module.
* @param mixed[] $data Data containing elements.
* @type string 'html' Desired output including HTML.
* @type string[] 'allowed_tags' (optional) List of allowed tags to render as HTML.
*/
$this->messageManager->addComplexSuccessMessage($identifer, $data);
```
## Usage
```php
protected messageManager;
public function __construct(
...
\Magento\Framework\Message\ManagerInterface $messageManager,
...
) {
$this->messageManager = $messageManager;
...
}
$this->messageManager->addComplexSuccessMessage('withHtml', [
'html' => 'This is bold text! And this is not.',
'allowed_tags' => ['b'],
]);
```

## License
[MIT](https://opensource.org/licenses/MIT)