4

I'm trying to use the addComplexSuccessMessage function on admin custom module, but I get an empty message.

The code I have is the following:

/etc/di.xml

    <!-- Admin HTML Complex Messages -->
    <type name="Magento\Framework\View\Element\Message\MessageConfigurationsPool">
        <arguments>
            <argument name="configurationsMap" xsi:type="array">
                <item name="createDocumentSuccessMessage" xsi:type="array">
                    <item name="renderer" xsi:type="const">\Magento\Framework\View\Element\Message\Renderer\BlockRenderer::CODE</item>
                    <item name="data" xsi:type="array">
                        <item name="template" xsi:type="string">Invoicing_Moloni::messages/createDocumentSuccessMessage.phtml</item>
                    </item>
                </item>
            </argument>
        </arguments>
    </type>

view/adminhtml/templates/messages/createDocumentSuccessMessage.phtml

<?php
// @codingStandardsIgnoreFile
/** @var \Magento\Framework\View\Element\Template $block */
?>

<?= $block->escapeHtml(__(
    'Document was sucessefuly created: <a href="%1">Open document</a>.',
    $block->getData('document_url')),
    ['a']
);

Controller/Adminhtml/Documents/Create.php

$this->messageManager->addComplexSuccessMessage(
            'createDocumentSuccessMessage',
            [
                'document_url' => $this->_url->getUrl('document/url')
            ]
        );

I can't seem to understand why I get this empty message: enter image description here

If anyone could help, I would really appreciate

1 Answer 1

3

Found a couple things I was doing wrong. First, the messages folder must be inside the adminhtml/templates; Second, I was editing the etc/di.xml while I should be adding that code to etc/adminhtml/di.xml

For all that have some problems with complexMessages, I'll leave this post :)

2
  • 1
    I am still getting the plain text of anchor tag in addComplexSuccessMessage. I have followed the same way provided by you. I am using Magento 2.3.4. Commented Mar 20, 2020 at 7:15
  • Don't be like me and forget to run setup:di:compile after you change di.xml...
    – Imanuel
    Commented Dec 28, 2020 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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