@@ -6,28 +6,35 @@ error_mapping
66
77**type**: ``array`` **default**: ``empty``
88
9- This option permitsto modify the default targetof errors.
10-
11- Imagine a custom method named ``matchingCityAndZipCode`` validates
12- whether the cityand zip code matches.
13- Unfortunately, thereis no" matchingCityAndZipCode" fieldin your form,
14- soall that Symfony cando for youis display the error on topof the form.
15-
16- With customized error mapping, you cando better:
17- make the error be mappedto the city field.
18-
19- Here are the rulesto understand the leftand the right sideof the mapping:
20-
21- * The left side containsproperty paths.
22- *If the violationis generated on aproperty or methodof aclass ,
23- its pathis simply propertyName.
24- *If the violationis generated on an entryof an ``array ``
25- or ``ArrayAccess``object , theproperty pathis ``[indexName]``.
26- * You can construct nestedproperty paths by concatenating them,
27- separating properties by dots,
28- *for example: ``addresses[work].matchingCityAndZipCode``
29- * The left sideof the error mapping also accepts a dot ``.``,
30- which refersto the field itself.
31- That means that any error addedto the fieldis addedto the given
32- nested field instead.
33- * The right side contains simply the namesof fieldsin the form.
9+ This option allows you to modify the target of a validation error.
10+
11+ Imagine you have a custom method named ``matchingCityAndZipCode`` that validates
12+ whether the city and zip code match. Unfortunately, there is no "matchingCityAndZipCode"
13+ field in your form, so all that Symfony can do is display the error on top
14+ of the form.
15+
16+ With customized error mapping, you can do better: map the error to the city
17+ field so that it displays above it::
18+
19+ public function setDefaultOptions(OptionsResolverInterface $resolver)
20+ {
21+ $resolver->setDefaults(array(
22+ 'error_mapping' => array(
23+ 'matchingCityAndZipCode' => 'city',
24+ ),
25+ ));
26+ }
27+
28+ Here are the rules for the left and the right side of the mapping:
29+
30+ * The left side contains property paths.
31+ * If the violation is generated on a property or method of a class, its path
32+ is simply "propertyName".
33+ * If the violation is generated on an entry of an ``array`` or ``ArrayAccess``
34+ object, the property path is ``[indexName]``.
35+ * You can construct nested property paths by concatenating them, separating
36+ properties by dots. For example: ``addresses[work].matchingCityAndZipCode``
37+ * The left side of the error mapping also accepts a dot ``.``, which refers
38+ to the field itself. That means that any error added to the field is added
39+ to the given nested field instead.
40+ * The right side contains simply the names of fields in the form.