Help: Custom Config XML Merging Error

On a new Magento 2.4.4 instance, I’ve created a custom XML config file with matching XSD and the supporting functionality using mostly virtual types:

 

When attempting to override/merge an existing config value in another module, I am getting an error during setup:upgrade: More than one node matching the query. Here’s an abstracted example to illustrate – the correct XML declaration has been used and the XSD utilised:

 

Vendor/Module/etc/custom_config.xml:

<config> <parent parent_attribute="parent_attribute_value"> <child child_attribute_1="child_attribute_1_value" child_attribute_2="child_attribute_2_value"/> </parent> </config> 

 

Vendor/ModuleTwo/etc/custom_config.xml:

<config> <parent parent_attribute="parent_attribute_value"> <child child_attribute_2="different_child_attribute_2_value"/> </parent> </config> 

 

I’ve used a <virtualType> to declare my config reader class and with the following idAttributes config added via di.xml:

<virtualType name="VendorModuleModelConfigReader type="MagentoFrameworkConfigReaderFilesystem"> ... <argument name="idAttributes" xsi:type="array"> <item name="/config/parent" xsi:type="string">parent_attribute</item> <item name="/config/parent/child" xsi:type="string">child_attribute_1</item> </argument> ... </virtualType> 

 

Full code snippets:

 

Vendor/Module/etc/custom_config.xsd:

<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- Config Node --> <xs:element name="config"> <xs:complexType> <xs:sequence> <xs:element name="parent" type="parent" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <!-- Parent Node --> <xs:complexType name="parent"> <xs:sequence> <xs:element name="parent_attribute" type="attributeConfig" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="type" type="childType" use="required"/> </xs:complexType> <xs:simpleType name="childType"> <xs:restriction base="xs:string"> <xs:enumeration value="parent_attribute_value"/> <xs:enumeration value="parent_attribute_value_two"/> </xs:restriction> </xs:simpleType> <!-- Child Node --> <xs:complexType name="attributeConfig"> <xs:attribute name="child_attribute_1" type="xs:string" use="required"/> <xs:attribute name="child_attribute_2" type="xs:string" use="optional"/> </xs:complexType> </xs:schema> 

 

Vendor/Module/etc/di.xml:

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <virtualType name="VendorModuleModelConfigData" type="MagentoFrameworkConfigData"> <arguments> <argument name="cacheId" xsi:type="string">vendor_module_custom_config_cache</argument> <argument name="reader" xsi:type="object">VendorModuleModelConfigReader</argument> </arguments> </virtualType> <virtualType name="VendorModuleModelConfigReader" type="MagentoFrameworkConfigReaderFilesystem"> <arguments> <argument name="converter" xsi:type="object">VendorModuleModelConfigConverter</argument> <argument name="fileName" xsi:type="string">custom_config.xml</argument> <argument name="idAttributes" xsi:type="array"> <item name="/config/parent" xsi:type="string">parent_attribute</item> <item name="/config/parent/child" xsi:type="string">child_attribute_1</item> </argument> <argument name="schemaLocator" xsi:type="object">VendorModuleModelConfigSchemaLocator</argument> </arguments> </virtualType> <virtualType name="VendorModuleModelConfigSchemaLocator" type="MagentoFrameworkConfigGenericSchemaLocator"> <arguments> <argument name="moduleName" xsi:type="string">Vendor_Module</argument> <argument name="schema" xsi:type="string">custom_config.xsd</argument> </arguments> </virtualType> </config> 

submitted by /u/magentothrowaway123
[link] [comments]