Transforming data
Last updated
Was this helpful?
Last updated
Was this helpful?
Basic concepts of transformers are explained below. Transformers are often used with , instructions for independant usage appears below. Also see full details on all .
Transformers come in three types:
Single value transformers are used to transform an individual value as it is accessed from data (array or object). This transformer can be used when setting up .
You need to pass the property path to the property you want to retrieve via a value transformer (e.g. '[date]'
). See for details on how to define a property path.
For example, this returns a DateTime object from $data['date']
:
A value transformer loops through all data applying the transformation to each value.
For example this sets all empty values to null to help return predictable data:
A data transformer acts on data as a whole.
For example this maps data values stored in $data['item']['category']
to local values:
Single value transformers have the isReadable()
method to test whether that value can be accessed. If a single value transformer cannot be transformed it returns null
.
If all values or data transformers cannot transform data they skip over it. These transformers contain a canTransform()
method which is used to check the data value is of the correct type to be transformed. This helps avoid unwanted errors.
If a data transformers implements the NotTransformedInterface
interface then you have access to two methods to help determine what data was not transformed. This can be useful, for example, if you map values and want to access any old values that did not map to new values.
See available .
See available .
See available .