Skip over navigation
Documentation
You are currently viewing documentation for a previously released version of OroCRM. See the latest long-term support version.

How to Add custom User Validation Constraints

The UserBundle from OroPlatform already ships a set of predefined validation constraints for the User entity. These rules are checked when a user is either being created or being modified.

You can define your own validation rules which are applied on top of the predefined rules when a User is being validated:

  • YAML
    1
    2
    3
    4
    5
    6
    # src/Acme/UserBundle/Resources/config/validation.yml
    Oro\Bundle\UserBundle\Entity\User:
        properties:
            enabled:
                - False:
                    groups: [Registration]
    
  • XML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    <!-- src/Acme/UserBundle/Resources/config/validation.xml -->
    <?xml version="1.0" encoding="UTF-8" ?>
    <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
            http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"
    >
        <class name="Oro\Bundle\UserBundle\Entity\User">
            <property name="password">
                <constraint name="False">
                    <option name="groups">
                        <value>Registration</value>
                    </option>
                </constraint>
            </property>
        </class>
    </constraint-mapping>
    

The example ensures that a user is not activated after being registered. The validation group associated to a constraint determines when the constraint is applied to the User entity:

Validation GroupApplied when a user is createdApplied when a user is modified
Registrationyesno
Rolesyesyes
No groupyesyes
Browse maintained versions:2.62.32.01.12
Forums
Back to top