Skip to content

Commit 286bcb8

Browse files
committed
Merge pull request #826 from mdpatrick/dyn_form_gen_update
Dynamic form gen update
2 parents 11f30fb + 87dca95 commit 286bcb8

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

cookbook/form/dynamic_form_generation.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ to an Event Subscriber::
5858

5959
use Symfony\Component\Form\AbstractType
6060
use Symfony\Component\Form\FormBuilder;
61-
use Acme\DemoBundle\Form\EventListener\MyFormListener;
61+
use Acme\DemoBundle\Form\EventListener\AddNameFieldSubscriber;
6262

6363
class ProductType extends AbstractType
6464
{
6565
public function buildForm(FormBuilder $builder, array $options)
6666
{
67-
$listener = new MyFormListener($builder->getFormFactory());
68-
$builder->addEventSubscriber($listener);
67+
$subscriber = new AddNameFieldSubscriber($builder->getFormFactory());
68+
$builder->addEventSubscriber($subscriber);
6969
$builder->add('price');
7070
}
7171

@@ -75,28 +75,28 @@ to an Event Subscriber::
7575
}
7676
}
7777

78-
The listener is passed the FormFactory object in its constructor so that our
79-
new listener class is capable of creating the form widget once it is notified
80-
of the dispatched event during form creation.
78+
The event subscriber is passed the FormFactory object in its constructor so
79+
that our new subscriber is capable of creating the form widget once it is
80+
notified of the dispatched event during form creation.
8181

82-
.. _`cookbook-forms-listener-class`:
82+
.. _`cookbook-forms-inside-subscriber-class`:
8383

84-
Inside the Listener Class
85-
-------------------------
84+
Inside the Event Subscriber Class
85+
---------------------------------
8686

8787
The goal is to create a "name" field *only* if the underlying Product object
88-
is new (e.g. hasn't been persisted to the database). Based on that, the listener
88+
is new (e.g. hasn't been persisted to the database). Based on that, the subscriber
8989
might look like the following::
9090

91-
// src/Acme/DemoBundle/Form/EventListener/MyFormListener.php
92-
namespace Acme\DemoBundle\Form\EventListener;
91+
// src/Acme/DemoBundle/Form/EventSubscriber/AddNameFieldSubscriber.php
92+
namespace Acme\DemoBundle\Form\EventSubscriber;
9393

9494
use Symfony\Component\Form\Event\DataEvent;
9595
use Symfony\Component\Form\FormFactoryInterface;
9696
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9797
use Symfony\Component\Form\FormEvents;
9898

99-
class MyFormListener implements EventSubscriberInterface
99+
class AddNameFieldSubscriber implements EventSubscriberInterface
100100
{
101101
private $factory;
102102
@@ -135,7 +135,7 @@ might look like the following::
135135

136136
.. caution::
137137

138-
It is easy to misunderstand the purpose of the ``if ($data == null)`` segment
138+
It is easy to misunderstand the purpose of the ``if (null === $data)`` segment
139139
of this event subscriber. To fully understand its role, you might consider
140140
also taking a look at the `Form class`_ and paying special attention to
141141
where setData() is called at the end of the constructor, as well as the

0 commit comments

Comments
 (0)