top of page
Writer's pictureVishesh Dwivedi

DI configuration arguments replacement with area fallback in Magento 2

I think this is the most important topic if you are preparing for any Adobe Commerce certification, you must have face at least one question related to this topic.


While creating UI component grid, you should inject grid collection class to the UI component's data provider in di.xml file. Doing this, have you ever encounter "Not registered handle" error?


The reason behind this is, you have injected the collection to data provider in etc/adminhtml/di.xml file like -


<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
    <arguments>
        <argument name="collections" xsi:type="array">
             <item name="custom_grid_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\CustomModel\Grid\Collection</item>
        </argument>
    </arguments>
 </type>

After doing this, your grid will start working but all other product, customer, orders, etc. grids will throw Not registered handle error.


The reason behind this is, all the other collections are injected in etc/di.xml file. So this is clear now, if we inject our custom grid collection in base di (etc/di.xml), then all the other grids will start working as well. But why this is happening?


As we know all the xml configurations, in Magento, first converted into PHP arrays then further processing takes place. So if we define any type class in both area di's (etc/di.xml and etc/adminhtml/di.xml) and modify their arguments, then it replace the base di arguments with admin di arguments instead of merging them, it means, configurations in different area are replaced at argument level. That's why, if you define data provider in admin area di.xml, then it overrides all the argument inject in base di of other modules.


**Configurations of same area got merged and if same configurations are defined in different areas, then they are overwritten by preferenced area configurations.


Thank you. Happy coding :)


82 views0 comments

Recent Posts

See All

Comments


bottom of page