@@ -86,6 +86,7 @@ location form type::
86
86
namespace Acme\HelloBundle\Form\Type;
87
87
88
88
use Symfony\Component\Form\FormBuilderInterface;
89
+ use Symfony\Component\OptionsResolver\OptionsResolverInterface;
89
90
90
91
class LocationType extends AbstractType
91
92
{
@@ -98,6 +99,13 @@ location form type::
98
99
->add('country', 'text');
99
100
}
100
101
102
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
103
+ {
104
+ $resolver->setDefaults(array(
105
+ 'virtual' => true
106
+ ));
107
+ }
108
+
101
109
public function getName()
102
110
{
103
111
return 'location';
@@ -118,15 +126,19 @@ Look at the result::
118
126
// CompanyType
119
127
public function buildForm(FormBuilderInterface $builder, array $options)
120
128
{
121
- $builder->add('foo', new LocationType());
129
+ $builder->add('foo', new LocationType(), array(
130
+ 'data_class' => 'Acme\HelloBundle\Entity\Company'
131
+ ));
122
132
}
123
133
124
134
.. code-block :: php
125
135
126
136
// CustomerType
127
137
public function buildForm(FormBuilderInterface $builder, array $options)
128
138
{
129
- $builder->add('bar', new LocationType());
139
+ $builder->add('bar', new LocationType(), array(
140
+ 'data_class' => 'Acme\HelloBundle\Entity\Customer'
141
+ ));
130
142
}
131
143
132
144
With the virtual option set to false (default behavior), the Form Component
0 commit comments