Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

Field Transformer

Field transformer can be used to transform fields by configuration.
For example this comes in handy if you're using the API Output Channel.


Service Registration

   autowire: true
   public: false
       - { name: form_builder.output_workflow.field_transform, identifier: phoneNumberTransformer }

Within the service, you're able to modify your value.


namespace AppBundle\FormBuilder\FieldTransformer;

use FormBuilderBundle\OutputWorkflow\FieldTransformerInterface;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberUtil;

class PhoneNumberTransformer implements FieldTransformerInterface
    public function getName(): string
        return 'Phone Number Transformer';

    public function getDescription(): ?string
        return 'Add your description here';

    public function transform($value, array $context): mixed
        $phoneUtil = PhoneNumberUtil::getInstance();
        $phoneInstance = $phoneUtil->parse($value, 'DE');
        return $phoneUtil->format($phoneInstance, PhoneNumberFormat::E164);