@@ -23,23 +23,35 @@ interface DataTransformerInterface
23
23
/**
24
24
* Transforms a value from the original representation to a transformed representation.
25
25
*
26
- * This method is called on two occasions inside a form field:
26
+ * This method is called when the form field is initialized with its default data, on
27
+ * two occasions for two types of transformers:
27
28
*
28
- * 1. When the form field is initialized with the data attached from the datasource (object or array).
29
- * 2. When data from a request is submitted using {@link Form::submit()} to transform the new input data
30
- * back into the renderable format. For example if you have a date field and submit '2009-10-10'
31
- * you might accept this value because its easily parsed, but the transformer still writes back
32
- * "2009/10/10" onto the form field (for further displaying or other purposes).
29
+ * 1. Model transformers which normalize the model data.
30
+ * This is mainly useful when the same form type (the same configuration)
31
+ * has to handle different kind of underlying data, e.g The DateType can
32
+ * deal with strings or \DateTime objects as input.
33
+ *
34
+ * 2. View transformers which adapt the normalized data to the view format.
35
+ * a/ When the form is simple, the value returned by convention is used
36
+ * directly in the view and thus can only be a string or an array. In
37
+ * this case the data class should be null.
38
+ *
39
+ * b/ When the form is compound the returned value should be an array or
40
+ * an object to be mapped to the children. Each property of the compound
41
+ * data will be used as model data by each child and will be transformed
42
+ * too. In this case data class should be the class of the object, or null
43
+ * when it is an array.
44
+ *
45
+ * All transformers are called in a configured order from model data to view value.
46
+ * At the end of this chain the view data will be validated against the data class
47
+ * setting.
33
48
*
34
49
* This method must be able to deal with empty values. Usually this will
35
50
* be NULL, but depending on your implementation other empty values are
36
51
* possible as well (such as empty strings). The reasoning behind this is
37
- * that value transformers must be chainable. If the transform() method
38
- * of the first value transformer outputs NULL, the second value transformer
39
- * must be able to process that value.
40
- *
41
- * By convention, transform() should return an empty string if NULL is
42
- * passed.
52
+ * that data transformers must be chainable. If the transform() method
53
+ * of the first data transformer outputs NULL, the second must be able to
54
+ * process that value.
43
55
*
44
56
* @param mixed $value The value in the original representation
45
57
*
@@ -54,7 +66,10 @@ public function transform($value);
54
66
* representation.
55
67
*
56
68
* This method is called when {@link Form::submit()} is called to transform the requests tainted data
57
- * into an acceptable format for your data processing/model layer.
69
+ * into an acceptable format.
70
+ *
71
+ * The same transformers are called in the reverse order so the responsibility is to
72
+ * return one of the types that would be expected as input of transform().
58
73
*
59
74
* This method must be able to deal with empty values. Usually this will
60
75
* be an empty string, but depending on your implementation other empty
0 commit comments