8000 Move Form Events article to the topic · symfony/symfony-docs@7ed9788 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ed9788

Browse files
committed
Move Form Events article to the topic
1 parent 6938b8c commit 7ed9788

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

form/dynamic_form_modification.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ how to customize your form based on three common use-cases:
2525
field.
2626

2727
If you wish to learn more about the basics behind form events, you can
28-
take a look at the :doc:`Form Events </components/form/form_events>`
29-
documentation.
28+
take a look at the :doc:`Form Events </form/events>` documentation.
3029

3130
.. _cookbook-form-events-underlying-data:
3231

components/form/form_events.rst renamed to form/events.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ depending on the request values::
2727
};
2828

2929
$form = $formFactory->createBuilder()
30-
// add form fields
30+
// ... add form fields
3131
->addEventListener(FormEvents::PRE_SUBMIT, $listener);
3232

3333
// ...
@@ -310,18 +310,22 @@ Creating and binding an event listener to the form is very easy::
310310
When you have created a form type class, you can use one of its methods as a
311311
callback for better readability::
312312

313-
// ...
313+
// src/AppBundle/Form/SubscriptionType.php
314+
namespace AppBundle\Form;
314315

316+
// ...
315317
class SubscriptionType extends AbstractType
316318
{
317319
public function buildForm(FormBuilderInterface $builder, array $options)
318320
{
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+
;
325329
}
326330

327331
public function onPreSetData(FormEvent $event)
@@ -341,6 +345,9 @@ Event subscribers have different uses:
341345

342346
.. code-block:: php
343347
348+
// src/AppBundle/Form/EventListener/AddEmailFieldListener.php
349+
namespace AppBundle\Form\EventListener;
350+
344351
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
345352
use Symfony\Component\Form\FormEvent;
346353
use Symfony\Component\Form\FormEvents;
@@ -388,8 +395,9 @@ Event subscribers have different uses:
388395
}
389396
}
390397
391-
To register the event subscriber, use the addEventSubscriber() method::
398+
To register the event subscriber, use the ``addEventSubscriber()`` method::
392399

400+
use AppBundle\Form\EventListener\AddEmailFieldListener;
393401
// ...
394402

395403
$form = $formFactory->createBuilder()

redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
/components/expression_language/index /components/expression_language
255255
/components/filesystem/introduction /components/filesystem
256256
/components/filesystem/index /components/filesystem
257+
/components/form/form_events /form/events
257258
/components/form/introduction /components/form
258259
/components/form/index /components/form
259260
/components/http_foundation/introduction /components/http_foundation

0 commit comments

Comments
 (0)
0