To implement your own form fields, you need to have a thorough understanding
of the data flow within a form field. A form field stores its data in three
different representations:
(1) the format required by the form's object
(2) a normalized format for internal processing
(3) the format used for display
A date field, for example, may store a date as "Y-m-d" string (1) in the
object. To facilitate processing in the field, this value is normalized
to a DateTime object (2). In the HTML representation of your form, a
localized string (3) is presented to and modified by the user.
In most cases, format (1) and format (2) will be the same. For example,
a checkbox field uses a Boolean value both for internal processing as for
storage in the object. In these cases you simply need to set a value
transformer to convert between formats (2) and (3). You can do this by
calling setValueTransformer() in the configure() method.
In some cases though it makes sense to make format (1) configurable. To
demonstrate this, let's extend our above date field to store the value
either as "Y-m-d" string or as timestamp. Internally we still want to
use a DateTime object for processing. To convert the data from string/integer
to DateTime you can set a normalization transformer by calling
setNormalizationTransformer() in configure(). The normalized data is then
converted to the displayed data as described before.