Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cookbook/form/dynamic_form_modification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Using an event listener, your form might look like this::

public function getName()
{
return 'acme_friend_message';
return 'friend_message';
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
Expand Down Expand Up @@ -389,29 +389,29 @@ it with :ref:`dic-tags-form-type`.

# app/config/config.yml
services:
acme.form.friend_message:
app.form.friend_message:
class: AppBundle\Form\Type\FriendMessageFormType
arguments: ["@security.context"]
tags:
- { name: form.type, alias: acme_friend_message }
- { name: form.type, alias: friend_message }

.. code-block:: xml

<!-- app/config/config.xml -->
<services>
<service id="acme.form.friend_message" class="AppBundle\Form\Type\FriendMessageFormType">
<service id="app.form.friend_message" class="AppBundle\Form\Type\FriendMessageFormType">
<argument type="service" id="security.context" />
<tag name="form.type" alias="acme_friend_message" />
<tag name="form.type" alias="friend_message" />
</service>
</services>

.. code-block:: php

// app/config/config.php
$definition = new Definition('AppBundle\Form\Type\FriendMessageFormType');
$definition->addTag('form.type', array('alias' => 'acme_friend_message'));
$definition->addTag('form.type', array('alias' => 'friend_message'));
$container->setDefinition(
'acme.form.friend_message',
'app.form.friend_message',
$definition,
array('security.context')
);
Expand All @@ -425,22 +425,22 @@ access to the form factory, you then use::
{
public function newAction(Request $request)
{
$form = $this->get('form.factory')->create('acme_friend_message');
$form = $this->get('form.factory')->create('friend_message');

// ...
}
}

If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::

$form = $this->createForm('acme_friend_message');
$form = $this->createForm('friend_message');

You can also easily embed the form type into another form::

// inside some other "form type" class
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('message', 'acme_friend_message');
$builder->add('message', 'friend_message');
}

.. _cookbook-form-events-submitted-data:
Expand Down