2

We had a custom block injected in the adminhtml section. This block is managed in a module (let's call it Vendor/Module) & it was working fine in Magento 2.1.*, following this methodology magento 2 - How to create a custom "admin" block and display it on an existing Admin page?

After upgrading to 2.2 the block has disappeared

I have checked for the concrete layout (in our case sales_order_view.xml) for any structural changes in the new version, but containers & blocks look the same as we had in 2.1.*

Any ideas for this?

This is the concrete layout file which worked fine in 2.1.*

app/code/Vendor/Module/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="order_info">
            <block class="Vendor\Module\Block\Adminhtml\Sales\Order\View\Form" name="our_unique_block_name" template="Vendor_Module::our_template.phtml"/>
        </referenceBlock>
    </body>
</page> 

UPDATE

Bounty: provide XML code to inject a block inside sales_order_view adminhtml layout, explaining how to place it in different sections of the page

3 Answers 3

3

Nero Phung answer was a good try, and led me to the real problem, looking for all sales_order_view appearances in the vendor folder

2.2 version adds Temando_Shipping module, which overrides sales_order_view layout

vendor/temando/module-shipping-m2/view/adminhtml/layout/sales_order_view.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="order_tab_info">
            <block class="Temando\Shipping\Block\Adminhtml\Sales\Order\View\Info" name="order_info" template="Temando_Shipping::sales/order/view/info.phtml">
                <container name="extra_customer_info"/>
            </block>
        </referenceContainer>
    </body>
</page>

So I could recover our custom block (using same XML layout as the one we used in 2.1.*) just by adding a module dependency

<module name="Vendor_Module">
    <sequence>
        <module name="Temando_Shipping"/>
    </sequence>
</module>
2
  • 1
    Congratulations!
    – Nero Phung
    Mar 12, 2018 at 16:39
  • 1
    Great work Raul, this saved me a lot of time debugging the same issue in our module on 2.2. Apr 20, 2018 at 16:57
2
+100

As I can see. Magento has added a new container inside block named order_info:

<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
    <container name="extra_customer_info"/>
</block>

So you can try to use this code below:

<referenceContainer name="extra_customer_info">
     <block class="Vendor\Module\Block\Adminhtml\Sales\Order\View\Form" name="our_unique_block_name" template="Vendor_Module::our_template.phtml"/>
</referenceContainer>

Hope it will help!

2
0

Can you try with referenceContainer?

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="order_info">
            <block class="Vendor\Module\Block\Adminhtml\Sales\Order\View\Form" name="our_unique_block_name" template="Vendor_Module::our_template.phtml"/>
        </referenceBlock>
    </body>
</page> 
3
  • What's the purpose of the change? Why using referenceContainer to reference a block? Mar 12, 2018 at 10:36
  • I use referenceBlock to modify block class (eg change template) and referenceContainer to include over blocks. And it work's
    – Aurélien
    Mar 12, 2018 at 15:16
  • But... I believe you cannot reference a block (using its name) with a referenceContainer instruction Mar 12, 2018 at 16:27

Your Answer

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

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