Skip to content

Commit 46c1c2e

Browse files
committed
complete config for form as a service
1 parent 182683c commit 46c1c2e

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

cookbook/form/dynamic_form_with_services.rst

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,34 @@ context, or by defining it as a service. This is the option we will show here.
138138
To define your form as a service, you simply add the configuration to your
139139
``config.yml`` file.
140140

141-
.. code-block:: yaml
142-
143-
acme.form.friend_message:
144-
class: Acme\WhateverBundle\FormType\FriendMessageType
145-
arguments: [@security.context]
146-
tags:
147-
- { name: form.type, alias: acme_friend_message}
141+
.. configuration-block::
142+
143+
.. code-block:: yaml
144+
145+
acme.form.friend_message:
146+
class: Acme\WhateverBundle\FormType\FriendMessageType
147+
arguments: [@security.context]
148+
tags:
149+
- { name: form.type, alias: acme_friend_message}
150+
151+
.. code-block:: xml
152+
153+
<services>
154+
<service id="acme.form.friend_message" class="Acme\WhateverBundle\FormType\FriendMessageType">
155+
<argument type="service" id="security.context" />
156+
<tag name="form.type" alias="acme_friend_message" />
157+
</service>
158+
</services>
159+
160+
.. code-block:: php
161+
162+
$definition = new Definition('Acme\WhateverBundle\FormType\FriendMessageType');
163+
$definition->addTag('form.type', array('alias' => 'acme_friend_message'));
164+
$container->setDefinition(
165+
'acme.form.friend_message',
166+
$definition,
167+
array('security.context')
168+
);
148169
149170
By adding the form as a service, we make sure that this form can now be used
150171
simply from anywhere. If you need to add it to another form, you will just need

0 commit comments

Comments
 (0)