FormBuilder
class FormBuilder extends FormConfigBuilder implements IteratorAggregate, FormBuilderInterface
A builder for creating {@link Form} instances.
Methods
Creates a new form builder.
Adds an event listener to an event on this form.
Adds an event subscriber for events on this form.
Appends / prepends a transformer to the view transformer chain.
Clears the view transformers.
Prepends / appends a transformer to the normalization transformer chain.
Clears the normalization transformers.
Returns the event dispatcher used to dispatch form events.
Returns the property path that the form should be mapped to.
Returns whether the form should be mapped to an element of its parent's data.
Returns whether the form's data should be modified by reference.
Returns whether the form should read and write the data of its parent.
Returns the form types used to construct the form.
Returns the view transformers of the form.
Returns the model transformers of the form.
Returns whether errors attached to the form will bubble to its parent.
Returns the data that should be returned when the form is empty.
Returns whether the attribute with the given name exists.
Returns the value of the given attribute.
Returns the class of the form data or null if the data is scalar or an array.
Returns the form factory used for creating new forms.
Returns the request handler used by the form.
Returns whether the form should be initialized upon creation.
Returns all options passed during the construction of the form.
Returns the value of a specific option.
Sets the value for an attribute.
Sets the attributes.
Set whether the form is disabled.
Sets the data used for the client data when no value is submitted.
Sets whether errors bubble up to the parent.
Sets whether this field is required to be filled out when submitted.
Sets the property path that the form should be mapped to.
Sets whether the form should be mapped to an element of its parent's data.
Sets whether the form's data should be modified by reference.
Sets whether the form should read and write the data of its parent.
Sets whether the form should be compound.
Sets the initial data of the form.
Locks the form's data to the data passed in the configuration.
Sets the form factory used for creating new forms.
Sets the target URL of the form.
Sets the HTTP method used by the form.
Sets the request handler used by the form.
Sets whether the form should be initialized automatically.
Builds and returns the form configuration.
Validates whether the given variable is a valid form name.
Returns whether the given variable contains a valid form name.
Adds a new field to this group. A field must have a unique name within the group. Otherwise the existing field is overwritten.
Creates a form builder.
Returns a child by name.
Removes the field with the given name.
Returns whether a field with the given name exists.
Returns the children.
{@inheritdoc}
{@inheritdoc}
Details
at line line 49
__construct(string|int $name, string $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory, array $options = array())
Creates a new form builder.
in FormConfigBuilder at line line 208
FormConfigBuilderInterface
addEventListener(string $eventName, callable $listener, int $priority)
Adds an event listener to an event on this form.
in FormConfigBuilder at line line 222
FormConfigBuilderInterface
addEventSubscriber(EventSubscriberInterface $subscriber)
Adds an event subscriber for events on this form.
in FormConfigBuilder at line line 236
FormConfigBuilderInterface
addViewTransformer(DataTransformerInterface $viewTransformer, bool $forcePrepend = false)
Appends / prepends a transformer to the view transformer chain.
The transform method of the transformer is used to convert data from the normalized to the view format. The reverseTransform method of the transformer is used to convert from the view to the normalized format.
in FormConfigBuilder at line line 254
FormConfigBuilderInterface
resetViewTransformers()
Clears the view transformers.
in FormConfigBuilder at line line 268
FormConfigBuilderInterface
addModelTransformer(DataTransformerInterface $modelTransformer, bool $forceAppend = false)
Prepends / appends a transformer to the normalization transformer chain.
The transform method of the transformer is used to convert data from the model to the normalized format. The reverseTransform method of the transformer is used to convert from the normalized to the model format.
in FormConfigBuilder at line line 286
FormConfigBuilderInterface
resetModelTransformers()
Clears the normalization transformers.
in FormConfigBuilder at line line 300
EventDispatcherInterface
getEventDispatcher()
Returns the event dispatcher used to dispatch form events.
in FormConfigBuilder at line line 312
string
getName()
Returns the name of the form used as HTTP parameter.
in FormConfigBuilder at line line 320
null|PropertyPathInterface
getPropertyPath()
Returns the property path that the form should be mapped to.
in FormConfigBuilder at line line 328
bool
getMapped()
Returns whether the form should be mapped to an element of its parent's data.
in FormConfigBuilder at line line 336
bool
getByReference()
Returns whether the form's data should be modified by reference.
in FormConfigBuilder at line line 344
bool
getInheritData()
Returns whether the form should read and write the data of its parent.
in FormConfigBuilder at line line 357
FormConfigBuilder
getVirtual()
deprecated
deprecated
Alias of {@link getInheritData()}.
in FormConfigBuilder at line line 367
bool
getCompound()
Returns whether the form is compound.
This property is independent of whether the form actually has children. A form can be compound and have no children at all, like for example an empty collection form.
in FormConfigBuilder at line line 375
ResolvedFormTypeInterface
getType()
Returns the form types used to construct the form.
in FormConfigBuilder at line line 383
DataTransformerInterface[]
getViewTransformers()
Returns the view transformers of the form.
in FormConfigBuilder at line line 391
DataTransformerInterface[]
getModelTransformers()
Returns the model transformers of the form.
in FormConfigBuilder at line line 399
DataMapperInterface
getDataMapper()
Returns the data mapper of the form.
in FormConfigBuilder at line line 407
bool
getRequired()
Returns whether the form is required.
in FormConfigBuilder at line line 415
bool
getDisabled()
Returns whether the form is disabled.
in FormConfigBuilder at line line 423
bool
getErrorBubbling()
Returns whether errors attached to the form will bubble to its parent.
in FormConfigBuilder at line line 431
mixed
getEmptyData()
Returns the data that should be returned when the form is empty.
in FormConfigBuilder at line line 439
array
getAttributes()
Returns additional attributes of the form.
in FormConfigBuilder at line line 447
bool
hasAttribute(string $name)
Returns whether the attribute with the given name exists.
in FormConfigBuilder at line line 455
mixed
getAttribute(string $name, mixed $default = null)
Returns the value of the given attribute.
in FormConfigBuilder at line line 463
mixed
getData()
Returns the initial data of the form.
in FormConfigBuilder at line line 471
string
getDataClass()
Returns the class of the form data or null if the data is scalar or an array.
in FormConfigBuilder at line line 479
bool
getDataLocked()
Returns whether the form's data is locked.
A form with locked data is restricted to the data passed in this configuration. The data can only be modified then by submitting the form.
in FormConfigBuilder at line line 487
FormFactoryInterface
getFormFactory()
Returns the form factory used for creating new forms.
in FormConfigBuilder at line line 495
string
getAction()
Returns the target URL of the form.
in FormConfigBuilder at line line 503
string
getMethod()
Returns the HTTP method used by the form.
in FormConfigBuilder at line line 511
RequestHandlerInterface
getRequestHandler()
Returns the request handler used by the form.
in FormConfigBuilder at line line 526
bool
getAutoInitialize()
Returns whether the form should be initialized upon creation.
in FormConfigBuilder at line line 534
array
getOptions()
Returns all options passed during the construction of the form.
in FormConfigBuilder at line line 542
bool
hasOption(string $name)
Returns whether a specific option exists.
in FormConfigBuilder at line line 550
mixed
getOption(string $name, mixed $default = null)
Returns the value of a specific option.
in FormConfigBuilder at line line 558
FormConfigBuilderInterface
setAttribute(string $name, mixed $value)
Sets the value for an attribute.
in FormConfigBuilder at line line 572
FormConfigBuilderInterface
setAttributes(array $attributes)
Sets the attributes.
in FormConfigBuilder at line line 586
FormConfigBuilderInterface
setDataMapper(DataMapperInterface $dataMapper = null)
Sets the data mapper used by the form.
in FormConfigBuilder at line line 600
FormConfigBuilderInterface
setDisabled(bool $disabled)
Set whether the form is disabled.
in FormConfigBuilder at line line 614
FormConfigBuilderInterface
setEmptyData(mixed $emptyData)
Sets the data used for the client data when no value is submitted.
in FormConfigBuilder at line line 628
FormConfigBuilderInterface
setErrorBubbling(bool $errorBubbling)
Sets whether errors bubble up to the parent.
in FormConfigBuilder at line line 642
FormConfigBuilderInterface
setRequired(bool $required)
Sets whether this field is required to be filled out when submitted.
in FormConfigBuilder at line line 656
FormConfigBuilderInterface
setPropertyPath(null|string|PropertyPathInterface $propertyPath)
Sets the property path that the form should be mapped to.
in FormConfigBuilder at line line 674
FormConfigBuilderInterface
setMapped(bool $mapped)
Sets whether the form should be mapped to an element of its parent's data.
in FormConfigBuilder at line line 688
FormConfigBuilderInterface
setByReference(bool $byReference)
Sets whether the form's data should be modified by reference.
in FormConfigBuilder at line line 702
FormConfigBuilderInterface
setInheritData(bool $inheritData)
Sets whether the form should read and write the data of its parent.
in FormConfigBuilder at line line 723
FormConfigBuilder
setVirtual(bool $inheritData)
deprecated
deprecated
Alias of {@link setInheritData()}.
in FormConfigBuilder at line line 733
FormConfigBuilderInterface
setCompound(bool $compound)
Sets whether the form should be compound.
in FormConfigBuilder at line line 747
FormConfigBuilderInterface
setType(ResolvedFormTypeInterface $type)
Set the types.
in FormConfigBuilder at line line 761
FormConfigBuilderInterface
setData(mixed $data)
Sets the initial data of the form.
in FormConfigBuilder at line line 775
FormConfigBuilderInterface
setDataLocked(bool $locked)
Locks the form's data to the data passed in the configuration.
A form with locked data is restricted to the data passed in this configuration. The data can only be modified then by submitting the form.
in FormConfigBuilder at line line 789
setFormFactory(FormFactoryInterface $formFactory)
Sets the form factory used for creating new forms.
in FormConfigBuilder at line line 803
FormConfigBuilderInterface
setAction(string $action)
Sets the target URL of the form.
in FormConfigBuilder at line line 817
FormConfigBuilderInterface
setMethod(string $method)
Sets the HTTP method used by the form.
in FormConfigBuilder at line line 841
FormConfigBuilderInterface
setRequestHandler(RequestHandlerInterface $requestHandler)
Sets the request handler used by the form.
in FormConfigBuilder at line line 855
FormConfigBuilderInterface
setAutoInitialize(bool $initialize)
Sets whether the form should be initialized automatically.
Should be set to true only for root forms.
at line line 195
FormConfigInterface
getFormConfig()
Builds and returns the form configuration.
in FormConfigBuilder at line line 890
static
validateName(string|int $name)
Validates whether the given variable is a valid form name.
in FormConfigBuilder at line line 918
static bool
isValidName(string $name)
Returns whether the given variable contains a valid form name.
A name is accepted if it
- is empty
- starts with a letter, digit or underscore
- contains only letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":")
at line line 59
FormBuilderInterface
add(string|int|FormBuilderInterface $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.
at line line 95
FormBuilderInterface
create(string $name, string|FormTypeInterface $type = null, array $options = array())
Creates a form builder.
at line line 115
FormBuilderInterface
get(string $name)
Returns a child by name.
at line line 135
FormBuilderInterface
remove(string $name)
Removes the field with the given name.
at line line 149
bool
has(string $name)
Returns whether a field with the given name exists.
at line line 169
array
all()
Returns the children.
at line line 183
count()
{@inheritdoc}
at line line 209
Form
getForm()
Creates the form.
at line line 235
getIterator()
{@inheritdoc}