Skip to content

Issues with registering custom UI components. #1724

Closed
@danslo

Description

@danslo

I am trying to register my own UI components. The first problem is the following:

We can only use view/base/ui_component/etc directory because Magento checks for files in $theme->getArea() but this value is NULL when component definition files are read.

Ok, not a big issue, I just place the definition.xml file in base directory for now:

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../etc/ui_definition.xsd">
    <someUniqueName class="NameSpace\Module\Ui\Component\Listing\Column\Some\Class\Here">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="template" xsi:type="string">ui/grid/some/template/path</item>
            </item>
        </argument>
    </someUniqueName>
</components>

And as you can see I define my own ui_definition.xsd file, which contains something like the following:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:include schemaLocation="../../../Magento/Ui/etc/ui_definition.xsd" />

    <!-- Create element. -->
    <xs:complexType name="someUniqueName">
        <xs:complexContent>
            <xs:extension base="ui_element">
                <xs:choice minOccurs="0" maxOccurs="unbounded">
                    <xs:group ref="configurable"/>
                </xs:choice>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Registering it in the system.-->
    <xs:complexType name="definition">
        <!-- xs:all already seems like a problem to me, shouldn't this be an xs:sequence? -->
        <xs:all>
            <xs:element type="someUniqueName" name="someUniqueName" />
        </xs:all>
    </xs:complexType>
</xs:schema>

But it seems like Magento\Framework\View\Element\UiComponent\Config\DomMerger::createDomDocument is always validating against app/code/Magento/Ui/etc/ui_definition.xsd instead of the one referenced in XML file. This causes validation to always fail and not being able to add custom UI component.

Message: Element 'someUniqueName': This element is not expected. Expected is one of ( tab, dataSource, paging, massaction, listing, form, fieldset, field, filters, columns ). Line: 4

I also found this definition.xml reference in devdocs, but it's simply an XML dump, it doesn't help me.

Maybe I'm doing something wrong. Hope someone can provide input here on how to add a UI component from a custom module.

Metadata

Metadata

Assignees

Labels

Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions