-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
FormEvents.php
113 lines (103 loc) · 4.02 KB
/
FormEvents.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Form;
use Symfony\Component\Form\Event\PostSetDataEvent;
use Symfony\Component\Form\Event\PostSubmitEvent;
use Symfony\Component\Form\Event\PreSetDataEvent;
use Symfony\Component\Form\Event\PreSubmitEvent;
use Symfony\Component\Form\Event\SubmitEvent;
/**
* To learn more about how form events work check the documentation
* entry at {@link https://symfony.com/doc/any/components/form/form_events.html}.
*
* To learn how to dynamically modify forms using events check the cookbook
* entry at {@link https://symfony.com/doc/any/cookbook/form/dynamic_form_modification.html}.
*
* @author Bernhard Schussek <[email protected]>
*/
final class FormEvents
{
/**
* The PRE_SUBMIT event is dispatched at the beginning of the Form::submit() method.
*
* It can be used to:
* - Change data from the request, before submitting the data to the form.
* - Add or remove form fields, before submitting the data to the form.
*
* @Event("Symfony\Component\Form\Event\PreSubmitEvent")
*/
public const PRE_SUBMIT = 'form.pre_submit';
/**
* The SUBMIT event is dispatched after the Form::submit() method
* has changed the view data by the request data, or submitted and mapped
* the children if the form is compound, and after reverse transformation
* to normalized representation.
*
* It's also dispatched just before the Form::submit() method transforms back
* the normalized data to the model and view data.
*
* So at this stage children of compound forms are submitted and synchronized, unless
* their transformation failed, but a parent would still be at the PRE_SUBMIT level.
*
* Since the current form is not synchronized yet, it is still possible to add and
* remove fields.
*
* @Event("Symfony\Component\Form\Event\SubmitEvent")
*/
public const SUBMIT = 'form.submit';
/**
* The FormEvents::POST_SUBMIT event is dispatched at the very end of the Form::submit().
*
* It this stage the model and view data may have been denormalized. Otherwise the form
* is desynchronized because transformation failed during submission.
*
* It can be used to fetch data after denormalization.
*
* The event attaches the current view data. To know whether this is the renormalized data
* or the invalid request data, call Form::isSynchronized() first.
*
* @Event("Symfony\Component\Form\Event\PostSubmitEvent")
*/
public const POST_SUBMIT = 'form.post_submit';
/**
* The FormEvents::PRE_SET_DATA event is dispatched at the beginning of the Form::setData() method.
*
* It can be used to:
* - Modify the data given during pre-population;
* - Keep synchronized the form depending on the data (adding or removing fields dynamically).
*
* @Event("Symfony\Component\Form\Event\PreSetDataEvent")
*/
public const PRE_SET_DATA = 'form.pre_set_data';
/**
* The FormEvents::POST_SET_DATA event is dispatched at the end of the Form::setData() method.
*
* This event can be used to modify the form depending on the final state of the underlying data
* accessible in every representation: model, normalized and view.
*
* @Event("Symfony\Component\Form\Event\PostSetDataEvent")
*/
public const POST_SET_DATA = 'form.post_set_data';
/**
* Event aliases.
*
* These aliases can be consumed by RegisterListenersPass.
*/
public const ALIASES = [
PreSubmitEvent::class => self::PRE_SUBMIT,
SubmitEvent::class => self::SUBMIT,
PostSubmitEvent::class => self::POST_SUBMIT,
PreSetDataEvent::class => self::PRE_SET_DATA,
PostSetDataEvent::class => self::POST_SET_DATA,
];
private function __construct()
{
}
}