Class

Symfony\Component\Form\FormBuilder

class FormBuilder

Methods

__construct(string $name, FormFactoryInterface $factory, EventDispatcherInterface $dispatcher, string $dataClass = null)

Constructor.

FormFactoryInterface getFormFactory()

Returns the associated form factory.

string getName()

Returns the name of the form.

FormBuilder setData(array $appData)

Updates the field with default data.

mixed getData()

Returns the data in the format needed for the underlying object.

FormBuilder setReadOnly(Boolean $readOnly)

Set whether the form is read only

Boolean getReadOnly()

Returns whether the form is read only.

FormBuilder setRequired(Boolean $required)

Sets whether this field is required to be filled out when bound.

Boolean getRequired()

Returns whether this field is required to be filled out when bound.

FormBuilder setErrorBubbling(type $errorBubbling)

Sets whether errors bubble up to the parent.

Boolean getErrorBubbling()

Returns whether errors bubble up to the parent.

FormBuilder addValidator(FormValidatorInterface $validator)

Adds a validator to the form.

array getValidators()

Returns the validators used by the form.

FormBuilder addEventListener($eventName, $listener, $priority)

Adds an event listener for events on this field

FormBuilder addEventSubscriber(EventSubscriberInterface $subscriber)

Adds an event subscriber for events on this field

FormBuilder appendNormTransformer(DataTransformerInterface $normTransformer)

Appends a transformer to the normalization transformer chain

FormBuilder prependNormTransformer(DataTransformerInterface $normTransformer)

Prepends a transformer to the client transformer chain

FormBuilder resetNormTransformers()

Clears the normalization transformers.

array getNormTransformers()

Returns all the normalization transformers.

FormBuilder appendClientTransformer(DataTransformerInterface $clientTransformer)

Appends a transformer to the client transformer chain

FormBuilder prependClientTransformer(DataTransformerInterface $clientTransformer)

Prepends a transformer to the client transformer chain

FormBuilder resetClientTransformers()

Clears the client transformers.

array getClientTransformers()

Returns all the client transformers.

FormBuilder setAttribute(string $name, string $value)

Sets the value for an attribute.

getAttribute(string $name)

Returns the value of the attributes with the given name.

hasAttribute(string $name)

Returns whether the form has an attribute with the given name.

array getAttributes()

Returns all the attributes.

FormBuilder setDataMapper(DataMapperInterface $dataMapper)

Sets the data mapper used by the form.

array getDataMapper()

Returns the data mapper used by the form.

FormBuilder setTypes(array $types)

Set the types.

array getTypes()

Return the types.

setEmptyData(mixed $emptyData)

Sets the data used for the client data when no value is bound.

mixed getEmptyData()

Returns the data used for the client data when no value is bound.

FormBuilder add(string|FormBuilder $child, string|FormTypeInterface $type = null, array $options = array())

Adds a new field to this group.

FormBuilder create(string $name, string|FormTypeInterface $type = null, array $options = array())

Creates a form builder.

FormBuilder get(string $name)

Returns a child by name.

FormBuilder remove(string $name)

Removes the field with the given name.

Boolean has(string $name)

Returns whether a field with the given name exists.

Form getForm()

Creates the form.

setCurrentLoadingType($type)

Details

at line 124
public __construct(string $name, FormFactoryInterface $factory, EventDispatcherInterface $dispatcher, string $dataClass = null)

Constructor.

Parameters

string $name
FormFactoryInterface $factory
EventDispatcherInterface $dispatcher
string $dataClass

at line 137
public FormFactoryInterface getFormFactory()

Returns the associated form factory.

Return Value

FormFactoryInterface The factory

at line 147
public string getName()

Returns the name of the form.

Return Value

string The form name

at line 159
public FormBuilder setData(array $appData)

Updates the field with default data.

Parameters

array $appData The data formatted as expected for the underlying object

Return Value

FormBuilder The current builder

at line 171
public mixed getData()

Returns the data in the format needed for the underlying object.

Return Value

mixed

at line 183
public FormBuilder setReadOnly(Boolean $readOnly)

Set whether the form is read only

Parameters

Boolean $readOnly Whether the form is read only

Return Value

FormBuilder The current builder

at line 195
public Boolean getReadOnly()

Returns whether the form is read only.

Return Value

Boolean Whether the form is read only

at line 207
public FormBuilder setRequired(Boolean $required)

Sets whether this field is required to be filled out when bound.

Parameters

Boolean $required

Return Value

FormBuilder The current builder

at line 219
public Boolean getRequired()

Returns whether this field is required to be filled out when bound.

Return Value

Boolean Whether this field is required

at line 231
public FormBuilder setErrorBubbling(type $errorBubbling)

Sets whether errors bubble up to the parent.

Parameters

type $errorBubbling

Return Value

FormBuilder The current builder

at line 243
public Boolean getErrorBubbling()

Returns whether errors bubble up to the parent.

Return Value

Boolean

at line 255
public FormBuilder addValidator(FormValidatorInterface $validator)

Adds a validator to the form.

Parameters

FormValidatorInterface $validator The validator

Return Value

FormBuilder The current builder

at line 267
public array getValidators()

Returns the validators used by the form.

Return Value

array An array of FormValidatorInterface

at line 279
public FormBuilder addEventListener($eventName, $listener, $priority)

Adds an event listener for events on this field

Parameters

$eventName
$listener
$priority

Return Value

FormBuilder The current builder

See also

Symfony\Component\EventDispatcher\EventDispatcherInterface::addListener

at line 293
public FormBuilder addEventSubscriber(EventSubscriberInterface $subscriber)

Adds an event subscriber for events on this field

Parameters

EventSubscriberInterface $subscriber

Return Value

FormBuilder The current builder

See also

Symfony\Component\EventDispatcher\EventDispatcherInterface::addSubscriber

at line 307
public FormBuilder appendNormTransformer(DataTransformerInterface $normTransformer)

Appends a transformer to the normalization transformer chain

Parameters

DataTransformerInterface $normTransformer

Return Value

FormBuilder The current builder

at line 321
public FormBuilder prependNormTransformer(DataTransformerInterface $normTransformer)

Prepends a transformer to the client transformer chain

Parameters

DataTransformerInterface $normTransformer

Return Value

FormBuilder The current builder

at line 333
public FormBuilder resetNormTransformers()

Clears the normalization transformers.

Return Value

FormBuilder The current builder

at line 345
public array getNormTransformers()

Returns all the normalization transformers.

Return Value

array An array of DataTransformerInterface

at line 357
public FormBuilder appendClientTransformer(DataTransformerInterface $clientTransformer)

Appends a transformer to the client transformer chain

Parameters

DataTransformerInterface $clientTransformer

Return Value

FormBuilder The current builder

at line 371
public FormBuilder prependClientTransformer(DataTransformerInterface $clientTransformer)

Prepends a transformer to the client transformer chain

Parameters

DataTransformerInterface $clientTransformer

Return Value

FormBuilder The current builder

at line 383
public FormBuilder resetClientTransformers()

Clears the client transformers.

Return Value

FormBuilder The current builder

at line 395
public array getClientTransformers()

Returns all the client transformers.

Return Value

array An array of DataTransformerInterface

at line 408
public FormBuilder setAttribute(string $name, string $value)

Sets the value for an attribute.

Parameters

string $name The name of the attribute
string $value The value of the attribute

Return Value

FormBuilder The current builder

at line 420
public getAttribute(string $name)

Returns the value of the attributes with the given name.

Parameters

string $name The name of the attribute

at line 430
public hasAttribute(string $name)

Returns whether the form has an attribute with the given name.

Parameters

string $name The name of the attribute

at line 440
public array getAttributes()

Returns all the attributes.

Return Value

array An array of attributes

at line 452
public FormBuilder setDataMapper(DataMapperInterface $dataMapper)

Sets the data mapper used by the form.

Parameters

DataMapperInterface $dataMapper

Return Value

FormBuilder The current builder

at line 464
public array getDataMapper()

Returns the data mapper used by the form.

Return Value

array An array of DataMapperInterface

at line 476
public FormBuilder setTypes(array $types)

Set the types.

Parameters

array $types An array FormTypeInterface

Return Value

FormBuilder The current builder

at line 488
public array getTypes()

Return the types.

Return Value

array An array of FormTypeInterface

at line 498
public setEmptyData(mixed $emptyData)

Sets the data used for the client data when no value is bound.

Parameters

mixed $emptyData

at line 510
public mixed getEmptyData()

Returns the data used for the client data when no value is bound.

Return Value

mixed

at line 528
public FormBuilder add(string|FormBuilder $child, string|FormTypeInterface $type = null, array $options = array())

Adds a new field to this group.

A field must have a unique name within the group. Otherwise the existing field is overwritten.

If you add a nested group, this group should also be represented in the object hierarchy.

Parameters

string|FormBuilder $child
string|FormTypeInterface $type
array $options

Return Value

FormBuilder The current builder

at line 565
public FormBuilder create(string $name, string|FormTypeInterface $type = null, array $options = array())

Creates a form builder.

Parameters

string $name The name of the form or the name of the property
string|FormTypeInterface $type The type of the form or null if name is a property
array $options The options

Return Value

FormBuilder The builder

at line 587
public FormBuilder get(string $name)

Returns a child by name.

Parameters

string $name The name of the child

Return Value

FormBuilder The builder for the child

Exceptions

FormException if the given child does not exist

at line 611
public FormBuilder remove(string $name)

Removes the field with the given name.

Parameters

string $name

Return Value

FormBuilder The current builder

at line 627
public Boolean has(string $name)

Returns whether a field with the given name exists.

Parameters

string $name

Return Value

Boolean

at line 637
public Form getForm()

Creates the form.

Return Value

Form The form

at line 665
public setCurrentLoadingType($type)

Parameters

$type