@@ -117,10 +117,58 @@ rather than::
117
117
118
118
$builder->add('name', new CustomType());
119
119
120
+ .. _override-validation :
121
+
120
122
Validation metadata
121
123
-------------------
122
124
123
- In progress...
125
+ Symfony loads all validation configuration files from every bundle and
126
+ combines them into one validation metadata tree. This means you are able to
127
+ add new constraints to a property, but you cannot override them.
128
+
129
+ To override this, the 3rd party bundle needs to have configuration for
130
+ :ref: `validation groups <book-validation-validation-groups >`. For instance,
131
+ the FOSUserBundle has this configuration. To create your own validation, add
132
+ the constraints to a new validation group:
133
+
134
+ .. configuration-block ::
135
+
136
+ .. code-block :: yaml
137
+
138
+ # src/Acme/UserBundle/Resources/config/validation.yml
139
+ Fos\UserBundle\Model\User :
140
+ properties :
141
+ plainPassword :
142
+ - NotBlank :
143
+ groups : [AcmeValidation]
144
+ - Length :
145
+ min : 6
146
+ minMessage : fos_user.password.short
147
+ groups : [AcmeValidation]
148
+
149
+ .. code-block :: xml
150
+
151
+ <!-- src/Acme/UserBundle/Resources/config/validation.xml -->
152
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
153
+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
154
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
155
+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
156
+
157
+ <class name =" Fos\UserBundle\Model\User" >
158
+ <property name =" password" >
159
+ <constraint name =" Length" >
160
+ <option name =" min" >6</option >
161
+ <option name =" minMessage" >fos_user.password.short</option >
162
+ <option name =" groups" >
163
+ <value >AcmeValidation</value >
164
+ </option >
165
+ </constraint >
166
+ </property >
167
+ </class >
168
+ </constraint-mapping >
169
+
170
+ Now, update the FosUserBundle configuration, so it uses your validation groups
171
+ instead of the original ones.
124
172
125
173
.. _override-translations :
126
174
0 commit comments