Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
Closed
Labels
Milestone
Description
The usage of theempty_data
option for forms should be documented.empty_data
allows to set the data set in the form when it is bound andsetData()
wasn't called before.
By default, this isnull
or, ifdata_class
is set, a new instance of that given class (created by using a no-args constructor).
The option can be overridden by setting a static value (1) or by setting a closure (2), that receives aFormInterface
instance as first argument. (2) should be preferred, as it only creates objects on demand.
(1)
public function getDefaultOptions(){ return array( 'empty_data' => new User($this->someDependency) );}
(2)
public function getDefaultOptions(){ return array( 'empty_data' => function (FormInterface $form) { return new User($form->get('username')->getData()); } );}