Skip to content

New di.xml Rejects <preferences> node #409

Closed
@astorm

Description

@astorm

In older version of Magento 2, it was possible to enact a Magento 1 class rewrite style behavior using a preferences node in a module's config.xml file.

<confg>
    <global>
        <di>
            <preferences>
                <Mage_Core_Model_Old>Packagename_Modulename_Mode_New</Mage_Core_Model_Old>
            </preferences>
        </di>
    </global>
</config>

However, rewrites specified in this manner are (appear to be?) ignored in the 2.0.0.0-dev50 version of Magento 2. This makes sense if a module's di.xml file is the new location for these nodes. However, creating the following nodes in di.xml

#File: app/code/Packagename/Modulename/etc/di.xml
<config>
            <preferences>
                <Mage_Core_Model_Old>Packagename_Modulename_Mode_New</Mage_Core_Model_Old>
            </preferences>
</config>

results in the following error.

Fatal error: Uncaught exception 'Exception' with message 'Invalid application config. Unknown node: preferences.' in /path/to/magento2/lib/Magento/ObjectManager/Config/Mapper/Dom.php on line 140
( ! ) Exception: Invalid application config. Unknown node: preferences. in /path/to/magento2/lib/Magento/ObjectManager/Config/Mapper/Dom.php on line 140
Call Stack
#   Time    Memory  Function    Location
1   0.0011  243056  {main}( )   ../index.php:0
2   0.0111  918664  Magento\Core\Model\EntryPoint\Http->processRequest( )   ../index.php:31
3   0.2358  4453456 Magento\Core\Model\AbstractEntryPoint->processException( )  ../Http.php:48
4   0.2358  4453792 Magento\Core\Model\AbstractEntryPoint->_init( ) ../AbstractEntryPoint.php:72
5   0.2358  4453928 Magento\Core\Model\ObjectManager->__construct( )    ../AbstractEntryPoint.php:110
6   0.2518  4822512 Magento\Core\Model\ObjectManager\ConfigLoader->load( )  ../ObjectManager.php:149
7   0.2519  4822632 Magento\Config\Reader\Filesystem->read( )   ../ConfigLoader.php:68
8   0.2540  4835528 Magento\Config\Reader\Filesystem->_readFiles( ) ../Filesystem.php:139
9   0.3746  4836216 Magento\ObjectManager\Config\Mapper\Dom->convert( ) ../Filesystem.php:179

If support for these so called <preferences/> rewrites have been dropped in favor of plugins, the release notes should indicate this. If support has not been dropped, support for preferences should be added to di.xml, or restored to config.xml.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions