Skip to main content

Input Transformer

Input Transformers will be applied, before a form gets pre-populated with given data.

Mostly this happens, if you're using a funnel output workflow. There, the form data gets normalized and needs to be transformed back, before we can populate a form with data.

Available Core Input Transformer

Available TransformerFieldService
date_transformerdate, datetime, time, birthday@OpenDxp\Bundle\FormBuilderBundle\Transformer\Output\DateDataObjectTransformer

Don't get confused!
Some core output transformers also supports input transformation. Since we won't the namespace that because of BC reasons, we'll keep it that way (for now).

Override default Input Transformer

If you want to transform the text field value for example, you need to add your own transformer. First, let FormBuilder know about your transformer.

You're also able to set up your custom input transform for your dynamic fields via the input_transformer configuration node.

form_builder:
types:
text:
input_transformer: text_input_transformer

Now you need to register your new transformer:

    App\OutputTransformer\TextInputTransformer:
autowire: true
tags:
- { name: form_builder.transformer.input, type: text_input_transformer }

After that, you have to set up a PHP-Service:

<?php

namespace App\InputTransformer;

use OpenDxp\Bundle\FormBuilderBundle\Model\FieldDefinitionInterface;
use OpenDxp\Bundle\FormBuilderBundle\Transformer\Input\InputTransformerInterface;

class TextInputTransformer implements InputTransformerInterface
{
public function getValueReverse(FieldDefinitionInterface $fieldDefinition, mixed $formValue): string
{
// manipulate or change the value
return $rawValue;
}
}

Custom input transformer

After you've created a custom form type (and/or you need it in a funnel output chanel), you may want to control the input values too. Configure your PHP Service same as explained above.

form_builder:
types:
your_custom_type:
input_transformer: custom_input_transformer

services:
App\OutputTransformer\MyCustomInputTransformer:
autowire: true
tags:
- { name: form_builder.transformer.input, type: custom_input_transformer }