8000 [Form] Merged various form events and added class FormEvent · symfony/symfony@33fecca · GitHub
[go: up one dir, main page]

Skip to content

Commit 33fecca

Browse files
committed
[Form] Merged various form events and added class FormEvent
1 parent bec8015 commit 33fecca

32 files changed

+334
-251
lines changed

UPGRADE-2.1.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,35 @@
671671
$builder->addViewTransformer(new MyTransformer());
672672
```
673673
674+
* The following events were deprecated and have a new equivalent:
675+
676+
* `FormEvents::SET_DATA`: `FormEvents::PRE_SET_DATA`
677+
* `FormEvents::BIND_CLIENT_DATA`: `FormEvents::PRE_BIND`
678+
* `FormEvents::BIND_NORM_DATA`: `FormEvents::BIND`
679+
680+
The deprecated events will be removed in Symfony 2.3.
681+
682+
Furthermore, the event classes `DataEvent` and `FilterDataEvent` were
683+
deprecated and replaced by the generic `FormEvent`. You are advised to
684+
code your listeners against the new event now. The deprecated events will
685+
be removed in Symfony 2.3.
686+
687+
Before:
688+
689+
```
690+
$builder->addListener(FormEvents::BIND_CLIENT_DATA, function (FilterDataEvent $event) {
691+
// ...
692+
});
693+
```
694+
695+
After:
696+
697+
```
698+
$builder->addListener(FormEvents::PRE_BIND, function (FormEvent $event) {
699+
// ...
700+
});
701+
```
702+
674703
### Validator
675704
676705
* The methods `setMessage()`, `getMessageTemplate()` and

src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717

1818
/**
@@ -30,10 +30,10 @@ static public function getSubscribedEvents()
3030
{
3131
// Higher priority than core MergeCollectionListener so that this one
3232
// is called before
33-
return array(FormEvents::BIND_NORM_DATA => array('onBindNormData', 10));
33+
return array(FormEvents::BIND => array('onBind', 10));
3434
}
3535

36-
public function onBindNormData(FilterDataEvent $event)
36+
public function onBind(FormEvent $event)
3737
{
3838
$collection = $event->getForm()->getData();
3939
$data = $event->getData();

src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/CsrfFormLoginBundle/Form/UserLoginFormType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Form\FormBuilderInterface;
1616
use Symfony\Component\Form\FormError;
1717
use Symfony\Component\Form\FormEvents;
18-
use Symfony\Component\Form\Event\FilterDataEvent;
18+
use Symfony\Component\Form\FormEvent;
1919
use Symfony\Component\HttpFoundation\Request;
2020
use Symfony\Component\Security\Core\SecurityContextInterface;
2121
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@@ -57,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5757
* request; however, we can match the expected behavior by checking the
5858
* session for an authentication error and last username.
5959
*/
60-
$builder->addEventListener(FormEvents::SET_DATA, function (FilterDataEvent $event) use ($request) {
60+
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($request) {
6161
if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
6262
$error = $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
6363
} else {

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,10 @@ CHANGELOG
124124
* `finishView`
125125
in FormTypeInterface and FormTypeExtensionInterface
126126
* [BC BREAK] no options are passed to `getParent` of FormTypeInterface anymore
127+
* deprecated DataEvent and FilterDataEvent in favor of the new FormEvent which is
128+
now passed to all events thrown by the component
129+
* FormEvents::BIND now replaces FormEvents::BIND_NORM_DATA
130+
* FormEvents::PRE_SET_DATA now replaces FormEvents::SET_DATA
131+
* FormEvents::PRE_BIND now replaces FormEvents::BIND_CLIENT_DATA
132+
* deprecated FormEvents::SET_DATA, FormEvents::BIND_CLIENT_DATA and
133+
FormEvents::BIND_NORM_DATA

src/Symfony/Component/Form/Event/DataEvent.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
use Symfony\Component\EventDispatcher\Event;
1515
use Symfony\Component\Form\FormInterface;
1616

17+
/**
18+
* @author Bernhard Schussek <bschussek@gmail.com>
19+
*
20+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Code against
21+
* {@link \Symfony\Component\Form\FormEvent} instead.
22+
*/
1723
class DataEvent extends Event
1824
{
1925
private $form;
@@ -50,4 +56,14 @@ public function getData()
5056
{
5157
return $this->data;
5258
}
59+
60+
/**
61+
* Allows updating with some filtered data
62+
*
63+
* @param mixed $data
64+
*/
65+
public function setData($data)
66+
{
67+
$this->data = $data;
68+
}
5369
}

src/Symfony/Component/Form/Event/FilterDataEvent.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111

1212
namespace Symfony\Component\Form\Event;
1313

14+
/**
15+
* @author Bernhard Schussek <bschussek@gmail.com>
16+
*
17+
* @deprecated Deprecated since version 2.1, to be removed in 2.3. Code against
18+
* {@link \Symfony\Component\Form\FormEvent} instead.
19+
*/
1420
class FilterDataEvent extends DataEvent
1521
{
16-
/**
17-
* Allows updating with some filtered data
18-
*
19-
* @param mixed $data
20-
*/
21-
public function setData($data)
22-
{
23-
$this->data = $data;
24-
}
2522
}

src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
1818

@@ -36,7 +36,7 @@ public function __construct(ChoiceListInterface $choiceList)
3636
$this->choiceList = $choiceList;
3737
}
3838

39-
public function onBindClientData(FilterDataEvent $event)
39+
public function preBind(FormEvent $event)
4040
{
4141
$values = (array) $event->getData();
4242
$indices = $this->choiceList->getIndicesForValues($values);
@@ -46,6 +46,6 @@ public function onBindClientData(FilterDataEvent $event)
4646

4747
static public function getSubscribedEvents()
4848
{
49-
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
49+
return array(FormEvents::PRE_BIND => 'preBind');
5050
}
5151
}

src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
1818

@@ -36,7 +36,7 @@ public function __construct(ChoiceListInterface $choiceList)
3636
$this->choiceList = $choiceList;
3737
}
3838

39-
public function onBindClientData(FilterDataEvent $event)
39+
public function preBind(FormEvent $event)
4040
{
4141
$value = $event->getData();
4242
$index = current($this->choiceList->getIndicesForValues(array($value)));
@@ -46,6 +46,6 @@ public function onBindClientData(FilterDataEvent $event)
4646

4747
static public function getSubscribedEvents()
4848
{
49-
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
49+
return array(FormEvents::PRE_BIND => 'preBind');
5050
}
5151
}

src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717

1818
/**
@@ -29,7 +29,7 @@ public function __construct($defaultProtocol = 'http')
2929
$this->defaultProtocol = $defaultProtocol;
3030
}
3131

32-
public function onBindNormData(FilterDataEvent $event)
32+
public function onBind(FormEvent $event)
3333
{
3434
$data = $event->getData();
3535

@@ -40,6 +40,6 @@ public function onBindNormData(FilterDataEvent $event)
4040

4141
static public function getSubscribedEvents()
4242
{
43-
return array(FormEvents::BIND_NORM_DATA => 'onBindNormData');
43+
return array(FormEvents::BIND => 'onBind');
4444
}
4545
}

src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\Form\FormEvents;
16-
use Symfony\Component\Form\Event\FilterDataEvent;
16+
use Symfony\Component\Form\FormEvent;
1717
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1818

1919
/**
@@ -50,15 +50,13 @@ public function __construct($allowAdd = false, $allowDelete = false)
5050
static public function getSubscribedEvents()
5151
{
5252
return array(
53-
FormEvents::BIND_NORM_DATA => 'onBindNormData',
53+
FormEvents::BIND => 'onBind',
5454
);
5555
}
5656

57-
public function onBindNormData(FilterDataEvent $event)
57+
public function onBind(FormEvent $event)
5858
{
5959
$dataToMergeInto = $event->getForm()->getNormData();
60-
61-
$form = $event->getForm();
6260
$data = $event->getData();
6361

6462
if (null === $data) {

src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\DataEvent;
16-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1716
use Symfony\Component\Form\FormFactoryInterface;
1817
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1918
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -67,11 +66,11 @@ static public function getSubscribedEvents()
6766
FormEvents::PRE_SET_DATA => 'preSetData',
6867
FormEvents::PRE_BIND => 'preBind',
6968
// (MergeCollectionListener, MergeDoctrineCollectionListener)
70-
FormEvents::BIND_NORM_DATA => array('onBindNormData', 50),
69+
FormEvents::BIND => array('onBind', 50),
7170
);
7271
}
7372

74-
public function preSetData(DataEvent $event)
73+
public function preSetData(FormEvent $event)
7574
{
7675
$form = $event->getForm();
7776
$data = $event->getData();
@@ -97,7 +96,7 @@ public function preSetData(DataEvent $event)
9796
}
9897
}
9998

100-
public function preBind(DataEvent $event)
99+
public function preBind(FormEvent $event)
101100
{
102101
$form = $event->getForm();
103102
$data = $event->getData();
@@ -131,7 +130,7 @@ public function preBind(DataEvent $event)
131130
}
132131
}
133132

134-
public function onBindNormData(FilterDataEvent $event)
133+
public function onBind(FormEvent $event)
135134
{
136135
$form = $event->getForm();
137136
$data = $event->getData();

src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Form\Extension\Core\EventListener;
1313

1414
use Symfony\Component\Form\FormEvents;
15-
use Symfony\Component\Form\Event\FilterDataEvent;
15+
use Symfony\Component\Form\FormEvent;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717

1818
/**
@@ -22,7 +22,7 @@
2222
*/
2323
class TrimListener implements EventSubscriberInterface
2424
{
25-
public function onBindClientData(FilterDataEvent $event)
25+
public function preBind(FormEvent $event)
2626
{
2727
$data = $event->getData();
2828

@@ -33,6 +33,6 @@ public function onBindClientData(FilterDataEvent $event)
3333

3434
static public function getSubscribedEvents()
3535
{
36-
return array(FormEvents::BIND_CLIENT_DATA => 'onBindClientData');
36+
return array(FormEvents::PRE_BIND => 'preBind');
3737
}
3838
}

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1515
use Symfony\Component\Form\FormEvents;
1616
use Symfony\Component\Form\FormError;
17-
use Symfony\Component\Form\Event\FilterDataEvent;
17+
use Symfony\Component\Form\FormEvent;
1818
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
1919

2020
/**
@@ -47,7 +47,7 @@ class CsrfValidationListener implements EventSubscriberInterface
4747
static public function getSubscribedEvents()
4848
{
4949
return array(
50-
FormEvents::BIND_CLIENT_DATA => 'onBindClientData',
50+
FormEvents::PRE_BIND => 'preBind',
5151
);
5252
}
5353

@@ -58,7 +58,7 @@ public function __construct($fieldName, CsrfProviderInterface $csrfProvider, $in
5858
$this->intention = $intention;
5959
}
6060

61-
public function onBindClientData(FilterDataEvent $event)
61+
public function preBind(FormEvent $event)
6262
{
6363
$form = $event->getForm();
6464
$data = $event->getData();

0 commit comments

Comments
 (0)
0