Skip to main content
Version: 2024.3

Environment Variable Transformers

Transformers are used to modify matrix values before they are processed by automation actions. Currently, only the asArray transformer is supported.

For a sample usage, refer to the transformers section of the configuration in the Variant Generator.

Implementing a Transformer

To implement your own transformer, you must extend the AbstractTransformer class. The abstract class implements the TransformerInterface and specifies abstract methods supports() and getTransformedValue().

You need to implement all the interface methods and the abstract methods of the abstract class.

Example:

<?php
declare(strict_types=1);

namespace App\Transformer\Types;

final class MyCustomTransformer extends AbstractTransformer
{
// type should match the transformer from your configuration (e.g. asArray)
public function supports(string $type): bool
{
return $type === 'myTransformer';
}

// transform the value here (e.g. cast to int)
public function getTransformedValue(mixed $value): int
{
return (int) $value;
}
}

Register a Transformer

Every transformer must be registered with the pimcore.copilot.interaction_transformer tag, e.g. in services.yaml. Registering a class without extending the AbstractTransformer will result in an exception.

App\Transformer\Types\MyCustomTransformer:
tags: ['pimcore.copilot.interaction_transformer']