FormBuilder
extends FormConfigBuilder
in package
implements
IteratorAggregate, FormBuilderInterface
A builder for creating {@link Form} instances.
Tags
Table of Contents
Interfaces
- IteratorAggregate
- FormBuilderInterface
Properties
- $locked : bool
- $action : string
- $attributes : array<string|int, mixed>
- $autoInitialize : bool
- $byReference : bool
- $children : array<string|int, FormBuilderInterface>
- The children of the form builder.
- $compound : bool
- $data : mixed
- $dataClass : string|null
- $dataLocked : bool
- $dataMapper : mixed
- $disabled : bool
- $dispatcher : mixed
- $emptyData : mixed
- $errorBubbling : bool
- $formFactory : mixed
- $inheritData : bool
- $isEmptyCallback : Closure|null
- $mapped : bool
- $method : string
- $modelTransformers : array<string|int, mixed>
- $name : string
- $nativeRequestHandler : NativeRequestHandler
- Caches a globally unique {@link NativeRequestHandler} instance.
- $options : array<string|int, mixed>
- $propertyPath : mixed
- $requestHandler : mixed
- $required : bool
- $type : mixed
- $unresolvedChildren : array<string|int, mixed>
- The data of children who haven't been converted to form builders yet.
- $viewTransformers : array<string|int, mixed>
Methods
- __construct() : mixed
- Creates an empty form configuration.
- add() : static
- Adds a new field to this group. A field must have a unique name within the group. Otherwise the existing field is overwritten.
- addEventListener() : $this
- Adds an event listener to an event on this form.
- addEventSubscriber() : $this
- Adds an event subscriber for events on this form.
- addModelTransformer() : $this
- Prepends / appends a transformer to the normalization transformer chain.
- addViewTransformer() : $this
- Appends / prepends a transformer to the view transformer chain.
- all() : array<string, self>
- Returns the children.
- count() : int
- create() : FormBuilderInterface
- Creates a form builder.
- get() : FormBuilderInterface
- Returns a child by name.
- getAction() : string
- {@inheritdoc}
- getAttribute() : mixed
- {@inheritdoc}
- getAttributes() : array<string|int, mixed>
- {@inheritdoc}
- getAutoInitialize() : bool
- {@inheritdoc}
- getByReference() : bool
- {@inheritdoc}
- getCompound() : bool
- {@inheritdoc}
- getData() : mixed
- {@inheritdoc}
- getDataClass() : string|null
- {@inheritdoc}
- getDataLocked() : bool
- {@inheritdoc}
- getDataMapper() : DataMapperInterface|null
- {@inheritdoc}
- getDisabled() : bool
- {@inheritdoc}
- getEmptyData() : mixed
- {@inheritdoc}
- getErrorBubbling() : bool
- {@inheritdoc}
- getEventDispatcher() : EventDispatcherInterface
- {@inheritdoc}
- getForm() : FormInterface
- Creates the form.
- getFormConfig() : FormConfigInterface
- Builds and returns the form configuration.
- getFormFactory() : FormFactoryInterface
- {@inheritdoc}
- getInheritData() : bool
- {@inheritdoc}
- getIsEmptyCallback() : callable|null
- {@inheritdoc}
- getIterator() : Traversable<string, FormBuilderInterface>
- {@inheritdoc}
- getMapped() : bool
- {@inheritdoc}
- getMethod() : string
- {@inheritdoc}
- getModelTransformers() : array<string|int, mixed>
- {@inheritdoc}
- getName() : string
- {@inheritdoc}
- getOption() : mixed
- {@inheritdoc}
- getOptions() : array<string|int, mixed>
- {@inheritdoc}
- getPropertyPath() : PropertyPathInterface|null
- {@inheritdoc}
- getRequestHandler() : RequestHandlerInterface
- {@inheritdoc}
- getRequired() : bool
- {@inheritdoc}
- getType() : ResolvedFormTypeInterface
- {@inheritdoc}
- getViewTransformers() : array<string|int, mixed>
- {@inheritdoc}
- has() : bool
- Returns whether a field with the given name exists.
- hasAttribute() : bool
- {@inheritdoc}
- hasOption() : bool
- {@inheritdoc}
- isValidName() : bool
- Returns whether the given variable contains a valid form name.
- remove() : static
- Removes the field with the given name.
- resetModelTransformers() : $this
- Clears the normalization transformers.
- resetViewTransformers() : $this
- Clears the view transformers.
- setAction() : $this
- Sets the target URL of the form.
- setAttribute() : $this
- Sets the value for an attribute.
- setAttributes() : $this
- Sets the attributes.
- setAutoInitialize() : $this
- Sets whether the form should be initialized automatically.
- setByReference() : $this
- Sets whether the form's data should be modified by reference.
- setCompound() : $this
- Sets whether the form should be compound.
- setData() : $this
- Sets the initial data of the form.
- setDataLocked() : $this
- Locks the form's data to the data passed in the configuration.
- setDataMapper() : $this
- Sets the data mapper used by the form.
- setDisabled() : $this
- Sets whether the form is disabled.
- setEmptyData() : $this
- Sets the data used for the client data when no value is submitted.
- setErrorBubbling() : $this
- Sets whether errors bubble up to the parent.
- setFormFactory() : mixed
- Sets the form factory used for creating new forms.
- setInheritData() : $this
- Sets whether the form should read and write the data of its parent.
- setIsEmptyCallback() : $this
- Sets the callback that will be called to determine if the model data of the form is empty or not.
- setMapped() : $this
- Sets whether the form should be mapped to an element of its parent's data.
- setMethod() : $this
- Sets the HTTP method used by the form.
- setPropertyPath() : $this
- Sets the property path that the form should be mapped to.
- setRequestHandler() : $this
- Sets the request handler used by the form.
- setRequired() : $this
- Sets whether this field is required to be filled out when submitted.
- setType() : $this
- Sets the resolved type.
- resolveChild() : FormBuilderInterface
- Converts an unresolved child into a {@link FormBuilderInterface} instance.
- resolveChildren() : mixed
- Converts all unresolved children into {@link FormBuilder} instances.
Properties
$locked
protected
bool
$locked
= false
$action
private
string
$action
= ''
$attributes
private
array<string|int, mixed>
$attributes
= []
$autoInitialize
private
bool
$autoInitialize
= false
$byReference
private
bool
$byReference
= true
$children
The children of the form builder.
private
array<string|int, FormBuilderInterface>
$children
= []
$compound
private
bool
$compound
= false
$data
private
mixed
$data
= null
$dataClass
private
string|null
$dataClass
$dataLocked
private
bool
$dataLocked
= false
$dataMapper
private
mixed
$dataMapper
= null
$disabled
private
bool
$disabled
= false
$dispatcher
private
mixed
$dispatcher
$emptyData
private
mixed
$emptyData
= null
$errorBubbling
private
bool
$errorBubbling
= false
$formFactory
private
mixed
$formFactory
$inheritData
private
bool
$inheritData
= false
$isEmptyCallback
private
Closure|null
$isEmptyCallback
= null
$mapped
private
bool
$mapped
= true
$method
private
string
$method
= 'POST'
$modelTransformers
private
array<string|int, mixed>
$modelTransformers
= []
$name
private
string
$name
$nativeRequestHandler
Caches a globally unique {@link NativeRequestHandler} instance.
private
static NativeRequestHandler
$nativeRequestHandler
$options
private
array<string|int, mixed>
$options
$propertyPath
private
mixed
$propertyPath
= null
$requestHandler
private
mixed
$requestHandler
$required
private
bool
$required
= true
$type
private
mixed
$type
$unresolvedChildren
The data of children who haven't been converted to form builders yet.
private
array<string|int, mixed>
$unresolvedChildren
= []
$viewTransformers
private
array<string|int, mixed>
$viewTransformers
= []
Methods
__construct()
Creates an empty form configuration.
public
__construct(string|null $name, string|null $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $name : string|null
-
The form name
- $dataClass : string|null
-
The class of the form's data
- $dispatcher : EventDispatcherInterface
- $factory : FormFactoryInterface
- $options : array<string|int, mixed> = []
add()
Adds a new field to this group. A field must have a unique name within the group. Otherwise the existing field is overwritten.
public
add(FormBuilderInterface|string $child[, string $type = null ][, array<string|int, mixed> $options = [] ]) : static
Parameters
- $child : FormBuilderInterface|string
- $type : string = null
- $options : array<string|int, mixed> = []
Return values
staticaddEventListener()
Adds an event listener to an event on this form.
public
addEventListener(string $eventName, callable $listener[, int $priority = 0 ]) : $this
Parameters
- $eventName : string
- $listener : callable
- $priority : int = 0
-
The priority of the listener. Listeners with a higher priority are called before listeners with a lower priority.
Return values
$thisaddEventSubscriber()
Adds an event subscriber for events on this form.
public
addEventSubscriber(EventSubscriberInterface $subscriber) : $this
Parameters
- $subscriber : EventSubscriberInterface
Return values
$thisaddModelTransformer()
Prepends / appends a transformer to the normalization transformer chain.
public
addModelTransformer(DataTransformerInterface $modelTransformer[, bool $forceAppend = false ]) : $this
Parameters
- $modelTransformer : DataTransformerInterface
- $forceAppend : bool = false
-
If set to true, append instead of prepending
Return values
$thisaddViewTransformer()
Appends / prepends a transformer to the view transformer chain.
public
addViewTransformer(DataTransformerInterface $viewTransformer[, bool $forcePrepend = false ]) : $this
Parameters
- $viewTransformer : DataTransformerInterface
- $forcePrepend : bool = false
-
If set to true, prepend instead of appending
Return values
$thisall()
Returns the children.
public
all() : array<string, self>
Return values
array<string, self>count()
public
count() : int
Return values
intcreate()
Creates a form builder.
public
create(string $name[, string $type = null ][, array<string|int, mixed> $options = [] ]) : FormBuilderInterface
Parameters
- $name : string
-
The name of the form or the name of the property
- $type : string = null
-
The type of the form or null if name is a property
- $options : array<string|int, mixed> = []
Return values
FormBuilderInterfaceget()
Returns a child by name.
public
get(string $name) : FormBuilderInterface
Parameters
- $name : string
Return values
FormBuilderInterfacegetAction()
{@inheritdoc}
public
getAction() : string
Return values
stringgetAttribute()
{@inheritdoc}
public
getAttribute(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
getAttributes()
{@inheritdoc}
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getAutoInitialize()
{@inheritdoc}
public
getAutoInitialize() : bool
Return values
boolgetByReference()
{@inheritdoc}
public
getByReference() : bool
Return values
boolgetCompound()
{@inheritdoc}
public
getCompound() : bool
Return values
boolgetData()
{@inheritdoc}
public
getData() : mixed
getDataClass()
{@inheritdoc}
public
getDataClass() : string|null
Return values
string|nullgetDataLocked()
{@inheritdoc}
public
getDataLocked() : bool
Return values
boolgetDataMapper()
{@inheritdoc}
public
getDataMapper() : DataMapperInterface|null
Return values
DataMapperInterface|nullgetDisabled()
{@inheritdoc}
public
getDisabled() : bool
Return values
boolgetEmptyData()
{@inheritdoc}
public
getEmptyData() : mixed
getErrorBubbling()
{@inheritdoc}
public
getErrorBubbling() : bool
Return values
boolgetEventDispatcher()
{@inheritdoc}
public
getEventDispatcher() : EventDispatcherInterface
Return values
EventDispatcherInterfacegetForm()
Creates the form.
public
getForm() : FormInterface
Return values
FormInterfacegetFormConfig()
Builds and returns the form configuration.
public
getFormConfig() : FormConfigInterface
Return values
FormConfigInterfacegetFormFactory()
{@inheritdoc}
public
getFormFactory() : FormFactoryInterface
Return values
FormFactoryInterfacegetInheritData()
{@inheritdoc}
public
getInheritData() : bool
Return values
boolgetIsEmptyCallback()
{@inheritdoc}
public
getIsEmptyCallback() : callable|null
Return values
callable|nullgetIterator()
{@inheritdoc}
public
getIterator() : Traversable<string, FormBuilderInterface>
Return values
Traversable<string, FormBuilderInterface>getMapped()
{@inheritdoc}
public
getMapped() : bool
Return values
boolgetMethod()
{@inheritdoc}
public
getMethod() : string
Return values
stringgetModelTransformers()
{@inheritdoc}
public
getModelTransformers() : array<string|int, mixed>
Return values
array<string|int, mixed>getName()
{@inheritdoc}
public
getName() : string
Return values
stringgetOption()
{@inheritdoc}
public
getOption(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
getOptions()
{@inheritdoc}
public
getOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getPropertyPath()
{@inheritdoc}
public
getPropertyPath() : PropertyPathInterface|null
Return values
PropertyPathInterface|nullgetRequestHandler()
{@inheritdoc}
public
getRequestHandler() : RequestHandlerInterface
Return values
RequestHandlerInterfacegetRequired()
{@inheritdoc}
public
getRequired() : bool
Return values
boolgetType()
{@inheritdoc}
public
getType() : ResolvedFormTypeInterface
Return values
ResolvedFormTypeInterfacegetViewTransformers()
{@inheritdoc}
public
getViewTransformers() : array<string|int, mixed>
Return values
array<string|int, mixed>has()
Returns whether a field with the given name exists.
public
has(string $name) : bool
Parameters
- $name : string
Return values
boolhasAttribute()
{@inheritdoc}
public
hasAttribute(string $name) : bool
Parameters
- $name : string
Return values
boolhasOption()
{@inheritdoc}
public
hasOption(string $name) : bool
Parameters
- $name : string
Return values
boolisValidName()
Returns whether the given variable contains a valid form name.
public
final static isValidName(string|null $name) : bool
A name is accepted if it
- is empty
- starts with a letter, digit or underscore
- contains only letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":")
Parameters
- $name : string|null
Return values
boolremove()
Removes the field with the given name.
public
remove(string $name) : static
Parameters
- $name : string
Return values
staticresetModelTransformers()
Clears the normalization transformers.
public
resetModelTransformers() : $this
Return values
$thisresetViewTransformers()
Clears the view transformers.
public
resetViewTransformers() : $this
Return values
$thissetAction()
Sets the target URL of the form.
public
setAction(string $action) : $this
Parameters
- $action : string
Return values
$thissetAttribute()
Sets the value for an attribute.
public
setAttribute(string $name, mixed $value) : $this
Parameters
- $name : string
- $value : mixed
-
The value of the attribute
Return values
$thissetAttributes()
Sets the attributes.
public
setAttributes(array<string|int, mixed> $attributes) : $this
Parameters
- $attributes : array<string|int, mixed>
Return values
$thissetAutoInitialize()
Sets whether the form should be initialized automatically.
public
setAutoInitialize(bool $initialize) : $this
Parameters
- $initialize : bool
-
True to initialize the form automatically, false to suppress automatic initialization. In the second case, you need to call manually.
Return values
$thissetByReference()
Sets whether the form's data should be modified by reference.
public
setByReference(bool $byReference) : $this
Parameters
- $byReference : bool
Return values
$thissetCompound()
Sets whether the form should be compound.
public
setCompound(bool $compound) : $this
Parameters
- $compound : bool
Return values
$thissetData()
Sets the initial data of the form.
public
setData(mixed $data) : $this
Parameters
- $data : mixed
-
The data of the form in model format
Return values
$thissetDataLocked()
Locks the form's data to the data passed in the configuration.
public
setDataLocked(bool $locked) : $this
Parameters
- $locked : bool
Return values
$thissetDataMapper()
Sets the data mapper used by the form.
public
setDataMapper([DataMapperInterface $dataMapper = null ]) : $this
Parameters
- $dataMapper : DataMapperInterface = null
Return values
$thissetDisabled()
Sets whether the form is disabled.
public
setDisabled(bool $disabled) : $this
Parameters
- $disabled : bool
Return values
$thissetEmptyData()
Sets the data used for the client data when no value is submitted.
public
setEmptyData(mixed $emptyData) : $this
Parameters
- $emptyData : mixed
-
The empty data
Return values
$thissetErrorBubbling()
Sets whether errors bubble up to the parent.
public
setErrorBubbling(bool $errorBubbling) : $this
Parameters
- $errorBubbling : bool
Return values
$thissetFormFactory()
Sets the form factory used for creating new forms.
public
setFormFactory(FormFactoryInterface $formFactory) : mixed
Parameters
- $formFactory : FormFactoryInterface
setInheritData()
Sets whether the form should read and write the data of its parent.
public
setInheritData(bool $inheritData) : $this
Parameters
- $inheritData : bool
Return values
$thissetIsEmptyCallback()
Sets the callback that will be called to determine if the model data of the form is empty or not.
public
setIsEmptyCallback(callable|null $isEmptyCallback) : $this
Parameters
- $isEmptyCallback : callable|null
Return values
$thissetMapped()
Sets whether the form should be mapped to an element of its parent's data.
public
setMapped(bool $mapped) : $this
Parameters
- $mapped : bool
Return values
$thissetMethod()
Sets the HTTP method used by the form.
public
setMethod(string $method) : $this
Parameters
- $method : string
Return values
$thissetPropertyPath()
Sets the property path that the form should be mapped to.
public
setPropertyPath(string|PropertyPathInterface|null $propertyPath) : $this
Parameters
- $propertyPath : string|PropertyPathInterface|null
-
The property path or null if the path should be set automatically based on the form's name
Return values
$thissetRequestHandler()
Sets the request handler used by the form.
public
setRequestHandler(RequestHandlerInterface $requestHandler) : $this
Parameters
- $requestHandler : RequestHandlerInterface
Return values
$thissetRequired()
Sets whether this field is required to be filled out when submitted.
public
setRequired(bool $required) : $this
Parameters
- $required : bool
Return values
$thissetType()
Sets the resolved type.
public
setType(ResolvedFormTypeInterface $type) : $this
Parameters
- $type : ResolvedFormTypeInterface
Return values
$thisresolveChild()
Converts an unresolved child into a {@link FormBuilderInterface} instance.
private
resolveChild(string $name) : FormBuilderInterface
Parameters
- $name : string
Return values
FormBuilderInterfaceresolveChildren()
Converts all unresolved children into {@link FormBuilder} instances.
private
resolveChildren() : mixed