Available transformers
Transforming single values
Single value transformers are used to transform an individual value as it is accessed from data. This is useful to ensure data values are of an expected type.
If the value cannot be found or cannot be transformed, then null is returned.
BooleanValue
Transform value to a boolean.
Usage:
By default, the following values are transformed to yes: 1, '1', 'true', 'yes', 'y'
And the following values are transformed to no: 0, '0', 'false', 'no', 'n'
Values are checked case-insensitively.
You can customise this by passing your own yes and no values to the constructor:
DateTimeValue
Transform value to a DateTime object.
Usage:
You can pass a datetime format to transform the string from by passing the format to the constructor:
FloatValue
Transform value to a float.
Usage:
IntegerValue
Transform value to an integer.
Usage:
Transforming all values
A value transformer loops through all data applying the transformation to each value.
HtmlEntitiesDecode
Decode data that has been encoded with HTML entities.
SetEmptyToNull
StripTags
Strip HTML tags.
Trim
Trims whitespace from start and end of values.
Transforming data
A data transformer acts on data as a whole.
MapValues
Maps values for one specific data field from old to new values. For example, updating category values to match local values.
The MapValues
class takes two arguments:
$mapping
- array of new value => old value/s
Usage:
Supports the NotTransformedInterface
interface, getNotTransformed()
returns an array of any old values that cannot be mapped to a new value.
RenameFields
The RenameFields
class takes one argument:
Usage:
Supports the NotTransformedInterface
interface, getNotTransformed()
returns an array of any new field names that cannot be renamed because the old fieldnames cannot be found.
Last updated
Was this helpful?