devtomic/magento2-module-messages

此软件包已被弃用且不再维护。作者建议使用 markshust/magento2-module-messages 软件包。

消息模块允许您使用HTML发送成功、通知、警告和错误消息。

安装: 16

依赖项: 0

建议者: 0

安全: 0

星星: 4

关注者: 1

分支: 0

开放问题: 0

类型:magento2-module

1.0.0 2018-11-06 21:29 UTC

This package is auto-updated.

Last update: 2019-02-19 16:17:06 UTC


README

Devtomic

Devtomic_Messages

使用<html>发送成功、通知、警告和错误消息

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

目录

摘要

默认情况下,当您在Magento中调用 $this->messageManager->addSuccessMessage 时,您无法传递自定义HTML到您的消息。这不会为您提供向访客提供定制消息的灵活性。

此模块提供显示自定义消息的能力,包括HTML,同时转义HTML以防止跨站脚本(XSS)攻击。

安装

composer require devtomic/magento2-module-messages
bin/magento module:enable Devtomic_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);

使用

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

许可

MIT