質問

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;
    }
}
役に立ちましたか?

解決

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 !!!

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top