-
Notifications
You must be signed in to change notification settings - Fork 2
09. Transform
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.
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.
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.
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.
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'.
Some transforms have parameters, others do not. The formatting and way you put the parameters in depend on what the transform expects.
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:
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
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
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.
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].*/
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
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
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:
- Must be in the
\yt\transform
namespace - Must implement the
transformInterface
. - Class name must match the filename.
- Must have the 3 functions declared.
- Must do a
composer dumpautoload
to see the new class. - To populate the catalog, you must also have a
$description
and$parameters
public parameters that will be read.