PHP Класс 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.
Автор: Bernhard Schussek ([email protected])
Наследование: extends Symfony\Component\Form\Configurable, implements Symfony\Component\Form\FieldInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$locale
$taintedData

Открытые методы

Метод Описание
__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}

Защищенные методы

Метод Описание
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.

Описание методов

__clone() публичный Метод

Clones this field.
public __clone ( )

__construct() публичный Метод

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

addError() публичный Метод

Adds an error to the field.
См. также: 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() публичный Метод

Binds POST data to the field, transforms and validates it.
public bind ( string | array $taintedData ) : boolean
$taintedData string | array The POST data
Результат boolean Whether the form is valid

denormalize() защищенный Метод

Reverse transforms a value if a normalization transformer is set.
protected denormalize ( string $value ) : mixed
$value string The value to reverse transform
Результат mixed

getData() публичный Метод

Returns the normalized data of the field.
public getData ( ) : mixed
Результат 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() публичный Метод

Returns the data of the field as it is displayed to the user.
public getDisplayedData ( ) : string | array
Результат 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() публичный Метод

Returns all errors
public getErrors ( ) : array
Результат array An array of errors that occured during binding

getId() публичный Метод

{@inheritDoc}
public getId ( )

getKey() публичный Метод

{@inheritDoc}
public getKey ( )

getName() публичный Метод

{@inheritDoc}
public getName ( )

getNormalizationTransformer() защищенный Метод

Returns the ValueTransformer.
protected getNormalizationTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
Результат Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

getNormalizedData() защищенный Метод

protected getNormalizedData ( )

getParent() публичный Метод

Returns the parent field.
public getParent ( ) : Symfony\Component\Form\FieldInterface
Результат Symfony\Component\Form\FieldInterface The parent field

getPropertyPath() публичный Метод

{@inheritDoc}
public getPropertyPath ( )

getTransformedData() защищенный Метод

Returns the data transformed by the value transformer
protected getTransformedData ( ) : string
Результат string

getValueTransformer() защищенный Метод

Returns the ValueTransformer.
protected getValueTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
Результат Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

hasErrors() публичный Метод

Returns weather there are errors.
public hasErrors ( ) : boolean
Результат boolean true if form is bound and not valid

injectLocale() защищенный Метод

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

isBound() публичный Метод

Returns whether the field is bound.
public isBound ( ) : boolean
Результат boolean true if the form is bound to input values, false otherwise

isDisabled() публичный Метод

{@inheritDoc}
public isDisabled ( )

isHidden() публичный Метод

Returns true if the widget is hidden.
public isHidden ( ) : boolean
Результат boolean true if the widget is hidden, false otherwise

isMultipart() публичный Метод

{@inheritDoc}
public isMultipart ( )

isRequired() публичный Метод

{@inheritDoc}
public isRequired ( )

isValid() публичный Метод

Returns whether the field is valid.
public isValid ( ) : boolean
Результат boolean

normalize() защищенный Метод

Normalizes the value if a normalization transformer is set
protected normalize ( mixed $value ) : string
$value mixed The value to transform
Результат string

processData() защищенный Метод

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
Результат mixed

reverseTransform() защищенный Метод

Reverse transforms a value if a value transformer is set.
protected reverseTransform ( string $value ) : mixed
$value string The value to reverse transform
Результат mixed

setData() публичный Метод

Updates the field with default data
См. также: FieldInterface
public setData ( $data )

setKey() публичный Метод

{@inheritDoc}
public setKey ( $key )

setLocale() публичный Метод

Sets the locale of this field.
См. также: Localizable
public setLocale ( $locale )

setNormalizationTransformer() защищенный Метод

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

setParent() публичный Метод

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

setPropertyPath() публичный Метод

{@inheritDoc}
public setPropertyPath ( $propertyPath )

setRequired() публичный Метод

{@inheritDoc}
public setRequired ( $required )

setValueTransformer() защищенный Метод

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

transform() защищенный Метод

Transforms the value if a value transformer is set.
protected transform ( mixed $value ) : string
$value mixed The value to transform
Результат string

updateFromObject() публичный Метод

{@inheritDoc}
public updateFromObject ( &$objectOrArray )

updateObject() публичный Метод

{@inheritDoc}
public updateObject ( &$objectOrArray )

Описание свойств

$locale защищенное свойство

protected $locale

$taintedData защищенное свойство

protected $taintedData