Skip to content

UI component definition.map.xml overlooks XSD-valid nodes #14140

@neillrobson

Description

@neillrobson

Preconditions

The issue was discovered in Magento 2.2.2 EE, but looks like it still exists in the 2.2-develop branch of this repository.

Steps to reproduce

  1. Create and configure a new UI form component with the following XML definition:
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  <!-- Include standard <argument>, <settings>, <dataSource> to create minimal form. -->
  <fieldset name="billing">
    <field name="shippingMethod" formElement="select">
      <formElements>
        <select>
          <settings>
            <options class="Magento\Shipping\Model\Config\Source\Allmethods" />
            <label>Shipping Method</label>
          </settings>
        </select>
      </formElements>
    </field>
  </fieldset>
</form>

Expected result

  1. The XML should validate with the provided XSD files. (It does.)
  2. When viewing the form in the browser, a dropdown select box with the label "Shipping Method" should be shown and populated with the values defined in the Allmethods class.

OR

  1. The XML should not validate with the provided XSD files, because the parser will not read the configuration correctly.

Actual result

  1. The XML validates.
  2. The dropdown select box is populated correctly, but the label is not shown.

However, the following code does display the label in the generated markup:

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
  <!-- Include standard <argument>, <settings>, <dataSource> to create minimal form. -->
  <fieldset name="billing">
    <field name="shippingMethod" formElement="select">
      <settings>
        <label>Shipping Method</label>
      </settings>
      <formElements>
        <select>
          <settings>
            <options class="Magento\Shipping\Model\Config\Source\Allmethods" />
          </settings>
        </select>
      </formElements>
    </field>
  </fieldset>
</form>

The issue seems to be how definition.map.xml is written, specifically around line 285 and 787. Settings such as <label>, which are common to many UI components, are read only from a top-level <settings> node, while component-specific settings such as <options> are read from the appropriate <settings> descendent of <formElements>.

This constraint/decision is perfectly understandable, but it is not represented in the corresponding XSD (see line 271 of ui_configuration.xsd, and the corresponding formElements group). Any child from the abstractSettings group (found here) is allowed (valid) within the <settings> nodes that are descendents of <formElements>, but none of them are read by the configuration reader because they aren't specified in definition.map.xml.

Potential Solutions

Depending on the architectural desires of the Magento team, this miscommunication could be fixed in a few ways:

  1. Adding the appropriate xpath mappings for abstractSettings within every component-specific settings mapping.
  2. Clarifying/constraining the XSD files to ensure that abstractSettings are only placed in top-level <settings> nodes, and component-specific settings remain isolated.

In short, the new UI component semantics function properly, but permit certain undefined behaviors that should be clarified in both the code itself and in documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: UiFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: 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 developmentProgress: PR CreatedIndicates that Pull Request has been created to fix issueReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseup for grabs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions