Skip to content

Merging of definition.xml fails on DOM elements with multiple children #24543

@HenKun

Description

@HenKun

Example: Adding a new export format to ExportButton.
It is not possible to add another export format to ExportButton by extending the defintion.xml.

Preconditions (*)

  1. Magento Version 2.3.2 & 2.3-develop
  2. Fresh install

Steps to reproduce (*)

  1. Create a new module
  2. Add {vendor}/{module}/view/base/ui_component/etc/definition.xml with following content:
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_definition.xsd">
    <exportButton>
        <settings>
            <options>
                <option name="customcsv" xsi:type="array">
                    <item name="value" xsi:type="string">customcsv</item>
                    <item name="label" xsi:type="string" translate="true">CUSTOM CSV</item>
                    <item name="url" xsi:type="string">{frontname}/export/gridToCustomCsv</item>
                </option>
            </options>
        </settings>
    </exportButton>
</components>
  1. Add controller {vendor}\{module}\Controller\Adminhtml\Export\GridToCustomCsv.php with content:
<?php

namespace {vendor}\{module}\Controller\Adminhtml\Export;

class GridToCustomCsv extends \Magento\Ui\Controller\Adminhtml\Export\GridToCsv
{
    const ADMIN_RESOURCE = 'Vendor_Module::gridtocustomcsv_export';
}
  1. Compile/upgrade etc.

  2. Go to admin sales order grid

Expected result (*)

  1. New entry "CUSTOM CSV" is added in export dropdown (in addition to csv and xml) above every grid, that already supports csv and xml export

Actual result (*)

  1. Exception \Magento\Framework\Exception\LocalizedException with message More than one node matching the query: /components/exportButton/settings/options/option, Xml is: ... is raised.

Reason

The original definition.xml from app/code/Magento/Ui/view/base/ui_component/etc/definition.xml contains the following part:

<exportButton class="Magento\Ui\Component\ExportButton" component="Magento_Ui/js/grid/export" displayArea="dataGridActions">
        <settings>
            <options>
                <option name="cvs" xsi:type="array">
                    <item name="value" xsi:type="string">csv</item>
                    <item name="label" xsi:type="string" translate="true">CSV</item>
                    <item name="url" xsi:type="string">mui/export/gridToCsv</item>
                </option>
                <option name="xml" xsi:type="array">
                    <item name="value" xsi:type="string">xml</item>
                    <item name="label" xsi:type="string" translate="true">Excel XML</item>
                    <item name="url" xsi:type="string">mui/export/gridToXml</item>
                </option>
            </options>
        </settings>
    </exportButton>

Two tags option reside in the options tag. In magento\framework\Config\Dom.php line 330 in _getMatchedNode Magento tries to find a matching tag option (stated in the new definition.xml) in the original defintion.xml without considering the name of the tag. It now finds two option tags in the original document, which leads to the thrown exception.

The name of the tag is not considered in this function, but one function above in _mergeNode line 165, which is too late. It should be totally valid to add another option tag to the options tag, given another name. Note that it works fine, if the original document would only contain one option under options.

Possible solution

The name (if available) should be already considered in _getMatchedNode. If this is done, then the check for the name in _mergeNode from line 174 to 183 can completely be left out, since _getMatchedNode would return null on non-matching nodes (consideriug the name if available) and _mergeNode would instantly use the else branch in line 214, beautifully eliminating the duplicate code in line 179 and 216 at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: Framework/XmlComponent: ImportExportEvent: mm20inIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P3May be fixed according to the position in the backlog.Progress: doneReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itfeature requeststale issue

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions