dantleech/symfony-form-array-to-delimited-string-transformer

Data transformer for SF form. Transforms delimited to string to array and vice-versa

Maintainers

👁 dantleech

Package info

github.com/dantleech/symfony-form-array-to-delimited-string-transformer

pkg:composer/dantleech/symfony-form-array-to-delimited-string-transformer

Statistics

Installs: 4 979

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 3

0.1 2014-10-11 06:33 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d6f9b8c350abb77c9a03efad4d649369ecada61b

  • dantleech <daniel.woop@dantleech.com>

This package is auto-updated.

Last update: 2026-06-11 06:33:25 UTC


README

👁 Build Status

This is a data transformer for the Symfony form framework.

It is meant for transforming text fields containing delimited strings to arrays.

Usage

You can use the data transformer as follows:

$form->add(
 $builder->create('tags', 'text')->addModelTransformer(
 new ArrayToDelimitedStringTransformer()
 )
);

This will transform the tags text field as follows:

// Tranform
array('one', 'two', 'three', 'four') === 'one, two, three, four'

// Reverse transform
' one , two , three, four,' === array('one', 'two', 'three', 'four')

Changing the delimiter

You can change the delimiting string with the first constructor argument:

new ArrayToDelimitedStringTransformer(';')

Will result in:

// Transform
array('one', 'two', 'three', 'four') === 'one; two; three; four'

// Reverse Transform
'one ; two;three ; four' => array('one', 'two', 'three')

Output padding

Additionally you can change the way in which the output is formatted with by setting the amount of whitespace (padding) before and after the text elements produced by a transformation:

new ArrayToDelimitedStringTransformer('%', 1, 1)

Will result in:

// Transform
array('one', 'two', 'three', 'four') === 'one % two % three % four'

// Reverse Transform
'one % two%three % four' => array('one', 'two', 'three')