PHP code example of devtomic / magento2-module-messages

1. Go to this page and download the library: Download devtomic/magento2-module-messages library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devtomic / magento2-module-messages example snippets


/**
 * 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'],
]);