@@ -27,7 +27,7 @@ depending on the request values::
27
27
};
28
28
29
29
$form = $formFactory->createBuilder()
30
- // add form fields
30
+ // ... add form fields
31
31
->addEventListener(FormEvents::PRE_SUBMIT, $listener);
32
32
33
33
// ...
@@ -310,18 +310,22 @@ Creating and binding an event listener to the form is very easy::
310
310
When you have created a form type class, you can use one of its methods as a
311
311
callback for better readability::
312
312
313
- // ...
313
+ // src/AppBundle/Form/SubscriptionType.php
314
+ namespace AppBundle\Form;
314
315
316
+ // ...
315
317
class SubscriptionType extends AbstractType
316
318
{
317
319
public function buildForm(FormBuilderInterface $builder, array $options)
318
320
{
319
- $builder->add('username', 'text');
320
- $builder->add('show_email', 'checkbox');
321
- $builder->addEventListener(
322
- FormEvents::PRE_SET_DATA,
323
- array($this, 'onPreSetData')
324
- );
321
+ $builder
322
+ ->add('username', 'text')
323
+ ->add('show_email', 'checkbox')
324
+ ->addEventListener(
325
+ FormEvents::PRE_SET_DATA,
326
+ array($this, 'onPreSetData')
327
+ )
328
+ ;
325
329
}
326
330
327
331
public function onPreSetData(FormEvent $event)
@@ -341,6 +345,9 @@ Event subscribers have different uses:
341
345
342
346
.. code-block :: php
343
347
348
+ // src/AppBundle/Form/EventListener/AddEmailFieldListener.php
349
+ namespace AppBundle\Form\EventListener;
350
+
344
351
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
345
352
use Symfony\Component\Form\FormEvent;
346
353
use Symfony\Component\Form\FormEvents;
@@ -388,8 +395,9 @@ Event subscribers have different uses:
388
395
}
389
396
}
390
397
391
- To register the event subscriber, use the addEventSubscriber() method::
398
+ To register the event subscriber, use the `` addEventSubscriber() `` method::
392
399
400
+ use AppBundle\Form\EventListener\AddEmailFieldListener;
393
401
// ...
394
402
395
403
$form = $formFactory->createBuilder()
0 commit comments