Transformations configuration

A number of properties relate to transforming the data during the import process. All of these properties are used during the “Transform data” step. They are sub-properties of the transformations property.

Properties

Property Data type Step/Scope
mapping Mapping configuration Transform data
rteEnabled boolean Transform data
trim boolean Transform data
userFunc array Transform data
value simple type (string, integer, boolean) Transform data

mapping

Type
Mapping configuration
Description
This property can be used to map values from the external data to values coming from some internal table. A typical example might be to match 2-letter country ISO codes to the uid of the “static_countries” table.
Scope
Transform data

value

Type
Simple type (string, integer, boolean)
Description
With this property, it is possible to set a fixed value for a given field. For example, this might be used to set a flag for all imported records.
Scope
Transform data

trim

Type
boolean
Description
If set to true, every value for this column will be trimmed during the transformation step.
Scope
Transform data

rteEnabled

Type
boolean
Description
If set to true when importing HTML data into a RTE-enable field, the imported data will go through the usual RTE transformation process on the way to the database.
Scope
Transform data

userFunc

Type
array
Description

This property can be used to define a function that will be called on each record to transform the data from the given field. See example below.

Example

Here is a sample setup referencing a user function:

$GLOBALS['TCA']['fe_users']['columns']['starttime']['external'] = array(
                0 => array(
                                'field' => 'start_date',
                                'transformations' => array(
                                                10 => (
                                                                'userFunc' => array(
                                                                                'class' => \Cobweb\ExternalImport\Task\DateTimeTransformation::class,
                                                                                'method' => 'parseDate'
                                                                )
                                                )
                                )
                )
);

A user function requires three parameters:

class
(string) Name of the class to be instantiated.
method
(string) Defines which method of the class should be called.
params
(array) Optional. Can contain any number of data, which will be passed to the method.

In the example above we are using a sample class provided by External Import that can be used to parse a date and either return it as a timestamp or format it using either of the PHP functions date() or strftime() .

For more details about creating a user function, please refer to the Developer’s Guide.

Scope
Transform data