-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Preconditions (*)
- Create a configurable object or virtual type e.g. composite
- It's impossible to add new items into array argument for different area.
- Related problem was reported here: https://stackoverflow.com/questions/34635615/magento-2-how-to-add-new-value-to-the-array-on-di-xml
Other should areas extend di configuration from global, or override only changed items/arguments. But in case with array
arguments the DI compilation process overrides entire array instead of merging its items.
See the code in methods:
\Magento\Framework\ObjectManager\Config\Config::_mergeConfiguration L248
\Magento\Framework\ObjectManager\Config\Config::_collectConfiguration L210
the arguments will be replaced
Steps to reproduce (*)
- Configure an object in global area
GLOBAL area di.xml
<virtualType name="SomeCompositeHandler" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_global" xsi:type="string">SomeHandlerGlobal</item>
</argument>
</arguments>
</virtualType>
- Modify the object in adminhtml area
ADMINHTML area di.xml
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
Expected result (*)
- The final object in code contains handlers from both areas as if it was defined like this in di.xml
Expected result for ADMINHTML area:
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_global" xsi:type="string">SomeHandlerGlobal</item>
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
Actual result (*)
- The
handlers
array argument got overridden instead of merged and works only the way defined in admin.
Actual result for ADMINHTML area:
<virtualType name="SomeCompositeHandler">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="some_handler_for_admin" xsi:type="string">SomeHandlerForAdmin</item>
</argument>
</arguments>
</virtualType>
So global handler is lost.
WORKAROUND:
Add all missed arguments from global area if you want to add additional ones for target area.
Might be also related to:
#34394
#28193
#31468
#15042
The issue is applicable also for cases when we follow guides like this:
https://devdocs.magento.com/guides/v2.4/inventory/source-selection-algorithms.html#configure-dixml
But what is I want to add new algorithm that is available only in certain area? Then all other algorithms added by modules will be removed, it's unexpected behavior!!
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status