PHP Class Symfony\Component\Form\Field

To implement your own form fields, you need to have a thorough understanding of the data flow within a form field. A form field stores its data in three different representations: (1) the format required by the form's object (2) a normalized format for internal processing (3) the format used for display A date field, for example, may store a date as "Y-m-d" string (1) in the object. To facilitate processing in the field, this value is normalized to a DateTime object (2). In the HTML representation of your form, a localized string (3) is presented to and modified by the user. In most cases, format (1) and format (2) will be the same. For example, a checkbox field uses a Boolean value both for internal processing as for storage in the object. In these cases you simply need to set a value transformer to convert between formats (2) and (3). You can do this by calling setValueTransformer() in the configure() method. In some cases though it makes sense to make format (1) configurable. To demonstrate this, let's extend our above date field to store the value either as "Y-m-d" string or as timestamp. Internally we still want to use a DateTime object for processing. To convert the data from string/integer to DateTime you can set a normalization transformer by calling setNormalizationTransformer() in configure(). The normalized data is then converted to the displayed data as described before.
Author: Bernhard Schussek ([email protected])
Inheritance: extends Symfony\Component\Form\Configurable, implements Symfony\Component\Form\FieldInterface
Afficher le fichier Open project: pmjones/php-framework-benchmarks Class Usage Examples

Protected Properties

Свойство Type Description
$locale
$taintedData

Méthodes publiques

Méthode Description
__clone ( ) Clones this field.
__construct ( $key, array $options = [] )
addError ( Symfony\Component\Form\FieldError $error, Symfony\Component\Form\PropertyPathIterator $pathIterator = null, $type = null ) Adds an error to the field.
bind ( string | array $taintedData ) : boolean Binds POST data to the field, transforms and validates it.
getData ( ) : mixed Returns the normalized data of the field.
getDisplayedData ( ) : string | array Returns the data of the field as it is displayed to the user.
getErrors ( ) : array Returns all errors
getId ( ) {@inheritDoc}
getKey ( ) {@inheritDoc}
getName ( ) {@inheritDoc}
getParent ( ) : Symfony\Component\Form\FieldInterface Returns the parent field.
getPropertyPath ( ) {@inheritDoc}
hasErrors ( ) : boolean Returns weather there are errors.
isBound ( ) : boolean Returns whether the field is bound.
isDisabled ( ) {@inheritDoc}
isHidden ( ) : boolean Returns true if the widget is hidden.
isMultipart ( ) {@inheritDoc}
isRequired ( ) {@inheritDoc}
isValid ( ) : boolean Returns whether the field is valid.
setData ( $data ) Updates the field with default data
setKey ( $key ) {@inheritDoc}
setLocale ( $locale ) Sets the locale of this field.
setParent ( Symfony\Component\Form\FieldInterface $parent = null ) {@inheritDoc}
setPropertyPath ( $propertyPath ) {@inheritDoc}
setRequired ( $required ) {@inheritDoc}
updateFromObject ( &$objectOrArray ) {@inheritDoc}
updateObject ( &$objectOrArray ) {@inheritDoc}

Méthodes protégées

Méthode Description
denormalize ( string $value ) : mixed Reverse transforms a value if a normalization transformer is set.
getNormalizationTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface Returns the ValueTransformer.
getNormalizedData ( )
getTransformedData ( ) : string Returns the data transformed by the value transformer
getValueTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface Returns the ValueTransformer.
injectLocale ( object $object ) Injects the locale into the given object, if set.
normalize ( mixed $value ) : string Normalizes the value if a normalization transformer is set
processData ( mixed $data ) : mixed Processes the bound reverse-transformed data.
reverseTransform ( string $value ) : mixed Reverse transforms a value if a value transformer is set.
setNormalizationTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $normalizationTransformer ) Sets the ValueTransformer.
setValueTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $valueTransformer ) Sets the ValueTransformer.
transform ( mixed $value ) : string Transforms the value if a value transformer is set.

Method Details

__clone() public méthode

Clones this field.
public __clone ( )

__construct() public méthode

public __construct ( $key, array $options = [] )
$options array

addError() public méthode

Adds an error to the field.
See also: FieldInterface
public addError ( Symfony\Component\Form\FieldError $error, Symfony\Component\Form\PropertyPathIterator $pathIterator = null, $type = null )
$error Symfony\Component\Form\FieldError
$pathIterator Symfony\Component\Form\PropertyPathIterator

bind() public méthode

Binds POST data to the field, transforms and validates it.
public bind ( string | array $taintedData ) : boolean
$taintedData string | array The POST data
Résultat boolean Whether the form is valid

denormalize() protected méthode

Reverse transforms a value if a normalization transformer is set.
protected denormalize ( string $value ) : mixed
$value string The value to reverse transform
Résultat mixed

getData() public méthode

Returns the normalized data of the field.
public getData ( ) : mixed
Résultat mixed When the field is not bound, the default data is returned. When the field is bound, the normalized bound data is returned if the field is valid, null otherwise.

getDisplayedData() public méthode

Returns the data of the field as it is displayed to the user.
public getDisplayedData ( ) : string | array
Résultat string | array When the field is not bound, the transformed default data is returned. When the field is bound, the bound data is returned.

getErrors() public méthode

Returns all errors
public getErrors ( ) : array
Résultat array An array of errors that occured during binding

getId() public méthode

{@inheritDoc}
public getId ( )

getKey() public méthode

{@inheritDoc}
public getKey ( )

getName() public méthode

{@inheritDoc}
public getName ( )

getNormalizationTransformer() protected méthode

Returns the ValueTransformer.
protected getNormalizationTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
Résultat Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

getNormalizedData() protected méthode

protected getNormalizedData ( )

getParent() public méthode

Returns the parent field.
public getParent ( ) : Symfony\Component\Form\FieldInterface
Résultat Symfony\Component\Form\FieldInterface The parent field

getPropertyPath() public méthode

{@inheritDoc}
public getPropertyPath ( )

getTransformedData() protected méthode

Returns the data transformed by the value transformer
protected getTransformedData ( ) : string
Résultat string

getValueTransformer() protected méthode

Returns the ValueTransformer.
protected getValueTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
Résultat Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

hasErrors() public méthode

Returns weather there are errors.
public hasErrors ( ) : boolean
Résultat boolean true if form is bound and not valid

injectLocale() protected méthode

The locale is injected only if the object implements Localizable.
protected injectLocale ( object $object )
$object object

isBound() public méthode

Returns whether the field is bound.
public isBound ( ) : boolean
Résultat boolean true if the form is bound to input values, false otherwise

isDisabled() public méthode

{@inheritDoc}
public isDisabled ( )

isHidden() public méthode

Returns true if the widget is hidden.
public isHidden ( ) : boolean
Résultat boolean true if the widget is hidden, false otherwise

isMultipart() public méthode

{@inheritDoc}
public isMultipart ( )

isRequired() public méthode

{@inheritDoc}
public isRequired ( )

isValid() public méthode

Returns whether the field is valid.
public isValid ( ) : boolean
Résultat boolean

normalize() protected méthode

Normalizes the value if a normalization transformer is set
protected normalize ( mixed $value ) : string
$value mixed The value to transform
Résultat string

processData() protected méthode

This method can be overridden if you want to modify the data entered by the user. Note that the data is already in reverse transformed format. This method will not be called if reverse transformation fails.
protected processData ( mixed $data ) : mixed
$data mixed
Résultat mixed

reverseTransform() protected méthode

Reverse transforms a value if a value transformer is set.
protected reverseTransform ( string $value ) : mixed
$value string The value to reverse transform
Résultat mixed

setData() public méthode

Updates the field with default data
See also: FieldInterface
public setData ( $data )

setKey() public méthode

{@inheritDoc}
public setKey ( $key )

setLocale() public méthode

Sets the locale of this field.
See also: Localizable
public setLocale ( $locale )

setNormalizationTransformer() protected méthode

Sets the ValueTransformer.
protected setNormalizationTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $normalizationTransformer )
$normalizationTransformer Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

setParent() public méthode

{@inheritDoc}
public setParent ( Symfony\Component\Form\FieldInterface $parent = null )
$parent Symfony\Component\Form\FieldInterface

setPropertyPath() public méthode

{@inheritDoc}
public setPropertyPath ( $propertyPath )

setRequired() public méthode

{@inheritDoc}
public setRequired ( $required )

setValueTransformer() protected méthode

Sets the ValueTransformer.
protected setValueTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $valueTransformer )
$valueTransformer Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

transform() protected méthode

Transforms the value if a value transformer is set.
protected transform ( mixed $value ) : string
$value mixed The value to transform
Résultat string

updateFromObject() public méthode

{@inheritDoc}
public updateFromObject ( &$objectOrArray )

updateObject() public méthode

{@inheritDoc}
public updateObject ( &$objectOrArray )

Property Details

$locale protected_oe property

protected $locale

$taintedData protected_oe property

protected $taintedData