Sf TIC Bundles

ListToStringTransformer
in package
implements DataTransformerInterface

Transforms between a list of values (simple array) and a string (concatenation).

Example: edit a multi-valued field with a simple textfield (with ", ") or textarea (with "\n") form

Table of Contents

Interfaces

DataTransformerInterface

Properties

$glue  : mixed
separator for split (ex: "," "\n" "|")
$sep  : mixed
$skip  : mixed
characters to clean with trim on values (or null to desactivate)
$trim  : mixed
separator for join (ex: ", " "\r\n" "|")

Methods

__construct()  : mixed
Construct the data transformer with parameters (separator, glue, trim & skip options).
reverseTransform()  : array<string|int, mixed>
Transforms a string into an array.
transform()  : string
Transforms an array into string.

Properties

$skip

characters to clean with trim on values (or null to desactivate)

protected mixed $skip = false

Methods

__construct()

Construct the data transformer with parameters (separator, glue, trim & skip options).

public __construct([string $sep = null ][, string $glue = null ][, bool $trim = true ][, bool $skip = false ]) : mixed
Parameters
$sep : string = null

Separator for split (default ",")

$glue : string = null

Separator for join (default according to $sep, ex: ", " for ",")

$trim : bool = true

If false, disable the trim on each values

$skip : bool = false

If true, skip items with empty value (null or "")

reverseTransform()

Transforms a string into an array.

public reverseTransform(string $values) : array<string|int, mixed>
Parameters
$values : string

All values into one string

Tags
throws
TransformationFailedException

If the given value is not a string.

Return values
array<string|int, mixed>

Array of values

transform()

Transforms an array into string.

public transform(mixed $values) : string
Parameters
$values : mixed
Tags
throws
TransformationFailedException

If the given value is not an array.

Return values
string

All values into one string


        
On this page

Search results