32
32
*
33
33
* (1) the "model" format required by the form's object
34
34
* (2) the "normalized" format for internal processing
35
- * (3) the "view" format used for display
35
+ * (3) the "view" format used for display simple fields
36
+ * or map children model data for compound fields
36
37
*
37
38
* A date field, for example, may store a date as "Y-m-d" string (1) in the
38
39
* object. To facilitate processing in the field, this value is normalized
39
40
* to a DateTime object (2). In the HTML representation of your form, a
40
- * localized string (3) is presented to and modified by the user.
41
+ * localized string (3) may be presented to and modified by the user, or it could be an array of values
42
+ * to be mapped to choices fields.
41
43
*
42
44
* In most cases, format (1) and format (2) will be the same. For example,
43
45
* a checkbox field uses a Boolean value for both internal processing and
44
- * storage in the object. In these cases you simply need to set a value
46
+ * storage in the object. In these cases you simply need to set a view
45
47
* transformer to convert between formats (2) and (3). You can do this by
46
48
* calling addViewTransformer().
47
49
*
48
50
* In some cases though it makes sense to make format (1) configurable. To
49
51
* demonstrate this, let's extend our above date field to store the value
50
52
* either as "Y-m-d" string or as timestamp. Internally we still want to
51
53
* use a DateTime object for processing. To convert the data from string/integer
52
- * to DateTime you can set a normalization transformer by calling
54
+ * to DateTime you can set a model transformer by calling
53
55
* addModelTransformer(). The normalized data is then converted to the displayed
54
56
* data as described before.
55
57
*
@@ -218,7 +220,7 @@ public function getPropertyPath()
218
220
}
219
221
220
222
if (null === $ this ->getName () || '' === $ this ->getName ()) {
221
- return ;
223
+ return null ;
222
224
}
223
225
224
226
$ parent = $ this ->parent ;
@@ -341,8 +343,8 @@ public function setData($modelData)
341
343
$ modelData = $ event ->getData ();
342
344
}
343
345
344
- // Treat data as strings unless a value transformer exists
345
- if (!$ this ->config ->getViewTransformers () && !$ this ->config ->getModelTransformers () && is_scalar ( $ modelData )) {
346
+ // Treat data as strings unless a transformer exists
347
+ if (is_scalar ( $ modelData ) && !$ this ->config ->getViewTransformers () && !$ this ->config ->getModelTransformers ()) {
346
348
$ modelData = (string ) $ modelData ;
347
349
}
348
350
@@ -1068,7 +1070,7 @@ public function createView(FormView $parent = null)
1068
1070
}
1069
1071
1070
1072
/**
1071
- * Normalizes the value if a normalization transformer is set.
1073
+ * Normalizes the value if a model transformer is set.
1072
1074
*
1073
1075
* @param mixed $value The value to transform
1074
1076
*
@@ -1090,7 +1092,7 @@ private function modelToNorm($value)
1090
1092
}
1091
1093
1092
1094
/**
1093
- * Reverse transforms a value if a normalization transformer is set.
1095
+ * Reverse transforms a value if a model transformer is set.
1094
1096
*
1095
1097
* @param string $value The value to reverse transform
1096
1098
*
@@ -1114,7 +1116,7 @@ private function normToModel($value)
1114
1116
}
1115
1117
1116
1118
/**
1117
- * Transforms the value if a value transformer is set.
1119
+ * Transforms the value if a view transformer is set.
1118
1120
*
1119
1121
* @param mixed $value The value to transform
1120
1122
*
@@ -1145,7 +1147,7 @@ private function normToView($value)
1145
1147
}
1146
1148
1147
1149
/**
1148
- * Reverse transforms a value if a value transformer is set.
1150
+ * Reverse transforms a value if a view transformer is set.
1149
1151
*
1150
1152
* @param string $value The value to reverse transform
1151
1153
*
0 commit comments