Parameter | Definition |
---|---|
HouseholdType::class | custom form class for the Household entity |
$household | an instance of the Household entity (usually created by $household = new Household(); ) |
$formOptions | an array of user-defined options to be passed to the form class, e.g.,$formOptions = array('foo' => 'bar'); |
When you create a form class the form fields are added in the public function buildForm(FormBuilderInterface $builder, array $options) {...}
function. The $options
parameter includes a set of default options such as attr
and label
. To enable your custom options to be available in the form class the options need to be initialized in configureOptions(OptionsResolver $resolver)
So for our real-world example:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Household',
'disabledOptions' => [],
));
}