0

I'm working to replace all layout <action> nodes on a M2 project. Looking at the below note on the M2 v2.2 documentation:

The instruction is deprecated. If the method implementation allows, use the for or to access block public API

https://devdocs.magento.com/guides/v2.2/frontend-dev-guide/layouts/xml-instructions.html

I got stuck while trying to replace the <action method="addTab">

<?xml version="1.0"?>
<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>
        <referenceBlock name="{{parent_block_name}}">
            <block class="{{block_class_name}}" name="{{block_name}}"/>
            <action method="addTab">
                <argument name="name" xsi:type="string">{{section_name}}</argument>
                <argument name="block" xsi:type="string">{{block_name}}</argument>
            </action>
        </referenceBlock>
    </body>
</page>

node and the documentation is a bit unclear. This layout xml file is in the Magento admin area.

enter image description here

What am I missing? Any guide will be helpful.

1
  • you want Move blocks to other container ?
    – user68116
    Commented Jun 7, 2018 at 12:16

1 Answer 1

3

Explanation of deprecation

the action tag for blocks is deprecated because, ideally, the layout files should be declarative not imperative.
The layout files should only determine the layout of the page. In simple terms... "This block goes there, the other one here. This block should not be there".

action tag is imperative. It tells the block it is called on to do something. The logic should be inside the block class itself and not the layout files.

For your specific problem
If you are building an admin form and you need to add tabs to it, then don't :). You should build the admin forms using ui-components and not the old ported M1 version using blocks and tabs.

General use of <action>
Avoid it if possible, but I know that in real life you may need it.
If you really want to go on with your form creation using tabs, just ignore the fact that is deprecated.

0

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.