markshust/magento2-module-messages

The Messages module allows you to send success, notice, warning and error messages with HTML.

Fund package maintenance!
markshust

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Stars: 56

Watchers: 5

Forks: 15

Open Issues: 1

Type:magento2-module

1.0.0 2018-11-06 21:29 UTC

This package is auto-updated.

Last update: 2024-04-13 15:50:42 UTC


README

Send success, notice, warning and error messages with <html>

Supported Magento Versions Latest Stable Version Composer Downloads Maintained - Yes 68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667

Table of contents

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

/**
 * 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

protected messageManager;
 
public function __construct(
    ... 
    \Magento\Framework\Message\ManagerInterface $messageManager,
    ...
) {
    $this->messageManager = $messageManager;
    ...
}

$this->messageManager->addComplexSuccessMessage('withHtml', [
    'html' => '<b>This is bold text!</b> And this is not.',
    'allowed_tags' => ['b'],
]);

Screenshot

License

MIT