Magento – Override base/ui_component/customer_form.xml

magento2overridesxml

I'm trying to override the following file and I need the changes to show in adminhtml.

vendor/magento/module-customer/view/base/ui_component/customer_form.xml

I have copied the file to the location below and made the changes.

app/code/[vendor]/[module]/view/base/ui_component/customer_form.xml

However the changes aren't showing up.

Tried a few different places such as overrides/adminhtml etc. I've also tried just including the fields/arguments I want to change and searching for the proper way to overwrite this file but haven't been able to get it working yet.

Edit: adding code of xml file after request

My first attempt was to copy the entire file and only change the value I needed (switching lastname validation to false). So that should be same as core except those two values. My second attempt to override the file only including the fields I changed is below.

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="lastname">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">customer</item>
                    <item name="validation" xsi:type="array">
                        <!-- this should work but doesn't appear to, needed to do a core hack instead -->
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                </item>
            </argument>
        </field>
    </fieldset>
    <fieldset name="address">
        <field name="lastname">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">address</item>
                    <item name="validation" xsi:type="array">
                        <!-- this should work but doesn't appear to, needed to do a core hack instead -->
                        <item name="required-entry" xsi:type="boolean">false</item>
                    </item>
                    <item name="imports" xsi:type="array">
                        <item name="default" xsi:type="string">${ $.provider }:data.customer.lastname</item>
                    </item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Best Answer

Try placing it in app/code/Vendor/Module/view/adminhtml/ui_component/customer_form.xml with the following content

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="address">
    <field name="lastname">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="validation" xsi:type="array">
                    <!-- this should work but doesn't appear to, needed to do a core hack instead -->
                    <item name="required-entry" xsi:type="boolean">false</item>
                </item>
            </item>
        </argument>
    </field>
</fieldset>
</form>

XML files are not overriden as they used to be in M1, instead you need to created file in your module and place what you want to add, then all should files be merged.

Related Topic