Skip to content

09. Transform

The Administrator edited this page May 6, 2020 · 2 revisions

Transform Tab

This section will allow you to define any possible transforms you want to perform on the values in your mappings (on the mapping tab).

So when you map the source -> destination fields, you have an intermediate transform that can alter the value in the middle. source -> transform -> destination. Handy for manipulating the data however you like.

Transform Group Instance

The transform groups collect one or more layers to change the data value. So rather than allow only a single change to happen, you can actually have as many changes as you like.

Transform Group ID

Label the transform groups to populate the mapper tab's select boxes. This will allow you to pick the transform group you wish to apply to each value.

Transform Group Layers

Here you can add as many layers as you like. Note that these layers are performed in order highest-to-lowest, so reorder the layers to the way you wish the processing to happen.

Transform

This is the selection box of the transform you wish to perform. For the list of transforms and what they do, see the below section 'transform catalog'.

Transform Parameters

Some transforms have parameters, others do not. The formatting and way you put the parameters in depend on what the transform expects.

Transform Catalog

This is a READ-ONLY section. Any changes will be removed and wiped on reload of the page. It's used for a purely informational section to help you understand what parameters to use on each transform.

Currently, there are the following transforms available:

best_image

This is used to select the best thumbnail image URL available from the API item. Doesn't require any parameters. However, it should be noted that it DOES expect a thumbnail array to be input. So you must use the source field location of the entire array in the mapping. Input = Thumbnail Array, Output = Single URL string of best image.

For example, the mapping would be:

Source Field      = snippet->thumbnails
Transform Group   = best_image
Destination       = Image
Destination Field = url

field_as_string

This will not use the source field as a location, rather use it as a literal string. You will need this to manually set specific destination fields to hard-coded values. For instance, the post_status value of a post will be set to draft by default. To change this, you'll need to set it to the string publish instead.

So, in this example, you would do:

Source Field      = publish
Transform Group   = field_as_string
Destination       = Post
Destination Field = post_status

none

Does nothing, but is good as a 'holder' of transform parameters. In case you want to switch of a particular layer, rather than delete it, you can set it to 'none' instead.

regex_remove

This performs a preg_replace() on the value. The value is replaced with nothing ''. So, it will be preg_replace($YOUR_PARAMETER, '', $source_value);.

The parameter is a regex string that you would use within the quotes of the preg_replace. (So don't add the single quotes).

Example parameters would be:

Remove all spaces from beginning of the line:

/^[\S].*/

string_remove

A more simple remove technique of strings within the value. Specify the string you wish to remove from the value only. Will perform a str_replace($YOUR_PARAMETER, '', $value) on the value.

Example string would be:

Minecraft

string_trim

This will shorten the value to the desired length. Specify an integer of length. All text after that length will be cut off. Will perform a substr($value, 0, $YOUR_PARAMETER);.

Example parameter would be:

55

Adding new transforms

All transforms are created in the /src/transform/transforms directory as interfaces of the transformInterface. They expect three functions:

interface transformInterface { 

    public function config($config);
    public function in($input);
    public function out();

}

Remember that you will need to do a composer dumpautoload to recognise the new transform class.

The $config will contain the passed parameters. The $input will be the value passed from the source field.

The out() function will return the desired output of the value.

Best to copy one of the existing transforms and alter as you see fit. Remember the following:

  1. Must be in the \yt\transform namespace
  2. Must implement the transformInterface.
  3. Class name must match the filename.
  4. Must have the 3 functions declared.
  5. Must do a composer dumpautoload to see the new class.
  6. To populate the catalog, you must also have a $description and $parameters public parameters that will be read.