1

What is the purpose of validation.xml file in Magento 2? When and where do we use them ?

I see there are couple of validation.xml files in Magento 2 directory.

For example: vendor/magento/module-customer/etc/validation.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<validation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Validator/etc/validation.xsd">
    <entity name="customer">
        <rules>
            <rule name="check_eav">
                <entity_constraints>
                    <constraint alias="eav_data_validator" class="Magento\Eav\Model\Validator\Attribute\Data" />
                </entity_constraints>
            </rule>
            <rule name="metadata_form_data">
                <entity_constraints>
                    <constraint alias="metadata_data_validator" class="Magento\Customer\Model\Metadata\Validator" />
                </entity_constraints>
            </rule>
        </rules>
        <groups>
            <group name="save">
                <uses>
                    <use rule="check_eav"/>
                </uses>
            </group>
            <group name="form">
                <uses>
                    <use rule="metadata_form_data"/>
                </uses>
            </group>
        </groups>
    </entity>

    <entity name="customer_address">
        <rules>
            <rule name="check_eav">
                <entity_constraints>
                    <constraint alias="eav_data_validator" class="Magento\Eav\Model\Validator\Attribute\Data" />
                </entity_constraints>
            </rule>
        </rules>
        <groups>
            <group name="save">
                <uses>
                    <use rule="check_eav"/>
                </uses>
            </group>
        </groups>
    </entity>
</validation>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.