- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.4k
Description
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 (*)
- Magento Version 2.3.2 & 2.3-develop
- Fresh install
Steps to reproduce (*)
- Create a new module
- Add {vendor}/{module}/view/base/ui_component/etc/definition.xmlwith 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>
- Add controller {vendor}\{module}\Controller\Adminhtml\Export\GridToCustomCsv.phpwith content:
<?php
namespace {vendor}\{module}\Controller\Adminhtml\Export;
class GridToCustomCsv extends \Magento\Ui\Controller\Adminhtml\Export\GridToCsv
{
    const ADMIN_RESOURCE = 'Vendor_Module::gridtocustomcsv_export';
}
- 
Compile/upgrade etc. 
- 
Go to admin sales order grid 
Expected result (*)
- 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 (*)
- Exception \Magento\Framework\Exception\LocalizedExceptionwith messageMore 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
Labels
Type
Projects
Status