1

I have use below code to add admin system notification and it is working fine but it add's only single notification , and i want to add multiple notification's using single file

enter image description here

does anyone know how can i do that ?

app\code\Vendor\Module\etc\di.xml

<?xml version="1.0" encoding="utf-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\Notification\MessageList">
        <arguments>
            <argument name="messages" xsi:type="array">
                <item name="custom_message" xsi:type="string">Vendor\Module\Model\Admin\Quote\Messages</item>
            </argument>
        </arguments>
    </type>
</config>

app\code\Vendor\Module\Model\Admin\Quote\Messages.php

<?php

namespace Vendor\Module\Model\Admin\Quote;

use Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection;
use Magento\Backend\Model\UrlInterface;
use Magento\Backend\Model\Auth\Session;
use Magento\Framework\Notification\MessageInterface;

class Messages implements MessageInterface
{

    protected $backendUrl;
    private $adminSessionInfoCollection;
    protected $authSession;

    public function __construct(
        Collection $adminSessionInfoCollection,
        UrlInterface $backendUrl,
        Session $authSession
    ) {
        $this->authSession = $authSession;
        $this->backendUrl = $backendUrl;
        $this->adminSessionInfoCollection = $adminSessionInfoCollection;
    }

    public function getText()
    {
        $message = __('Test Message 1 ');
        return $message;
    }
    public function getIdentity()
    {
        return md5('Test Message 1 ' . $this->authSession->getUser()->getLogdate());
    }
    public function isDisplayed()
    {
        return true;
    }
    public function getSeverity()
    {
      \Magento\Framework\Notification\MessageInterface::SEVERITY_CRITICAL;
    }
}
  • Can you please describe into some more detail, what you are looking for? – Dhiren Vasoya Oct 19 at 12:42
  • if i have two different message than how i can display that both message separately – Sanjay Shiyal Oct 19 at 13:03
  • Have you try any code for this one? then share. – Dhiren Vasoya Oct 19 at 13:13
  • i have only try above code, i am not able to get such a code that will add multiple separete notifications – Sanjay Shiyal Oct 21 at 11:11
0

i have got my problem solutions for multiple notifications with below code

app\code\Vendor\Extension\view\adminhtml\layout\default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceContainer name="global.notices">
        <block class="Magento\Backend\Block\Page\Notices" name="custom_notices" as="custom_notices" after="global_notices" template="Vendor_Extension::page/notices.phtml"/>
    </referenceContainer>
</page>

app\code\Vendor\Extension\view\adminhtml\templates\page\notices.phtml

 <div class="messages">
    <div class="message message-warning message-demo-mode">
         <?php echo __("Test Message 1"); ?>
    </div>
 </div>
 <div class="messages">
    <div class="message message-warning message-demo-mode">
         <?php echo __("Test Message 2"); ?>
    </div>
 </div>

I hope this code will help some one ...

Happy Coding !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.