2

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

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 :)

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.