FormBuilder
class FormBuilder extends FormConfigBuilder implements IteratorAggregate, FormBuilderInterface
A builder for creating {@link Form} instances.
Properties
protected bool | $locked | from FormConfigBuilder |
Methods
Creates an empty form configuration.
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.
Prepends / appends a transformer to the normalization transformer chain.
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 the data mapper 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 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.
Locks the form's data to the data passed in the configuration.
Sets the form factory used for creating new forms.
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}
Creates the form.
{@inheritdoc}
Details
__construct(string|int $name, string|null $dataClass, EventDispatcherInterface $dispatcher, FormFactoryInterface $factory, array $options = array())
Creates an empty form configuration.
$this
addEventListener(string $eventName, callable $listener, int $priority = 0)
Adds an event listener to an event on this form.
$this
addEventSubscriber(EventSubscriberInterface $subscriber)
Adds an event subscriber for events on this form.
$this
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.
$this
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.
EventDispatcherInterface
getEventDispatcher()
Returns the event dispatcher used to dispatch form events.
PropertyPathInterface|null
getPropertyPath()
Returns the property path that the form should be mapped to.
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.
string|null
getDataClass()
Returns the class of the form data or null if the data is scalar or an array.
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.
$this
setEmptyData(mixed $emptyData)
Sets the data used for the client data when no value is submitted.
$this
setRequired(bool $required)
Sets whether this field is required to be filled out when submitted.
$this
setPropertyPath(string|PropertyPathInterface|null $propertyPath)
Sets the property path that the form should be mapped to.
$this
setMapped(bool $mapped)
Sets whether the form should be mapped to an element of its parent's data.
$this
setByReference(bool $byReference)
Sets whether the form's data should be modified by reference.
$this
setInheritData(bool $inheritData)
Sets whether the form should read and write the data of its parent.
$this
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.
setFormFactory(FormFactoryInterface $formFactory)
Sets the form factory used for creating new forms.
$this
setRequestHandler(RequestHandlerInterface $requestHandler)
Sets the request handler used by the form.
$this
setAutoInitialize(bool $initialize)
Sets whether the form should be initialized automatically.
Should be set to true only for root forms.
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 (":")
FormBuilderInterface
add(string|int|FormBuilderInterface $child, string|null $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.
FormBuilderInterface
create(string $name, string|null $type = null, array $options = array())
Creates a form builder.