@@ -17,15 +17,16 @@ Creating the form type
17
17
18
18
Using an event listener, our form could be built like this::
19
19
20
- namespace Acme\WhateverBundle\FormType;
20
+ // src/Acme/DemoBundle/FormType/FriendMessageFormType.php
21
+ namespace Acme\DemoBundle\FormType;
21
22
22
23
use Symfony\Component\Form\AbstractType;
23
24
use Symfony\Component\Form\FormBuilderInterface;
24
25
use Symfony\Component\Form\FormEvents;
25
26
use Symfony\Component\Form\FormEvent;
26
27
use Symfony\Component\Security\Core\SecurityContext;
27
28
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
28
- use Acme\WhateverBundle \FormSubscriber\UserListener;
29
+ use Acme\DemoBundle \FormSubscriber\UserListener;
29
30
30
31
class FriendMessageFormType extends AbstractType
31
32
{
@@ -79,6 +80,7 @@ Customizing the form type
79
80
Now that we have all the basics in place, we can put everything in place and add
80
81
our listener::
81
82
83
+ // src/Acme/DemoBundle/FormType/FriendMessageFormType.php
82
84
class FriendMessageFormType extends AbstractType
83
85
{
84
86
private $securityContext;
@@ -104,7 +106,7 @@ our listener::
104
106
$userId = $user->getId();
105
107
106
108
$form_options = [
107
- 'class' => 'Acme\WhateverBundle \Document\User',
109
+ 'class' => 'Acme\DemoBundle \Document\User',
108
110
'multiple' => false,
109
111
'expanded' => false,
110
112
'property' => 'fullName',
@@ -136,30 +138,33 @@ controller. Either by creating it everytime and remembering to pass the security
136
138
context, or by defining it as a service. This is the option we will show here.
137
139
138
140
To define your form as a service, you simply add the configuration to your
139
- `` config.yml `` file .
141
+ configuration .
140
142
141
143
.. configuration-block ::
142
144
143
145
.. code-block :: yaml
144
146
147
+ # app/config/config.yml
145
148
acme.form.friend_message :
146
- class : Acme\WhateverBundle \FormType\FriendMessageType
149
+ class : Acme\DemoBundle \FormType\FriendMessageType
147
150
arguments : [@security.context]
148
151
tags :
149
152
- { name: form.type, alias: acme_friend_message}
150
153
151
154
.. code-block :: xml
152
155
156
+ <!-- app/config/config.xml -->
153
157
<services >
154
- <service id =" acme.form.friend_message" class =" Acme\WhateverBundle \FormType\FriendMessageType" >
158
+ <service id =" acme.form.friend_message" class =" Acme\DemoBundle \FormType\FriendMessageType" >
155
159
<argument type =" service" id =" security.context" />
156
160
<tag name =" form.type" alias =" acme_friend_message" />
157
161
</service >
158
162
</services >
159
163
160
164
.. code-block :: php
161
165
162
- $definition = new Definition('Acme\WhateverBundle\FormType\FriendMessageType');
166
+ // app/config/config.php
167
+ $definition = new Definition('Acme\DemoBundle\FormType\FriendMessageType');
163
168
$definition->addTag('form.type', array('alias' => 'acme_friend_message'));
164
169
$container->setDefinition(
165
170
'acme.form.friend_message',
0 commit comments