Skip to content
Permalink
Browse files

[Form] Deprecated bind() and isBound() in favor of submit() and isSub…

…mitted()
  • Loading branch information...
webmozart committed Apr 20, 2013
1 parent 5c53e6b commit 41b01279637bd260247fed8d44850644ddc89bf3
Showing with 719 additions and 520 deletions.
  1. +42 −7 UPGRADE-3.0.md
  2. +1 −1 src/Symfony/Bridge/Doctrine/Form/EventListener/MergeDoctrineCollectionListener.php
  3. +21 −21 src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypeTest.php
  4. +10 −10 src/Symfony/Component/Form/Button.php
  5. +6 −0 src/Symfony/Component/Form/CHANGELOG.md
  6. +4 −4 src/Symfony/Component/Form/DataTransformerInterface.php
  7. +6 −0 src/Symfony/Component/Form/Exception/AlreadyBoundException.php
  8. +22 −0 src/Symfony/Component/Form/Exception/AlreadySubmittedException.php
  9. +13 −2 src/Symfony/Component/Form/Extension/Core/EventListener/FixCheckboxInputListener.php
  10. +13 −2 src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php
  11. +13 −2 src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php
  12. +14 −2 src/Symfony/Component/Form/Extension/Core/EventListener/MergeCollectionListener.php
  13. +27 −4 src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php
  14. +13 −2 src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php
  15. +1 −1 src/Symfony/Component/Form/Extension/Core/Type/FormType.php
  16. +1 −1 src/Symfony/Component/Form/Extension/Core/Type/PasswordType.php
  17. +1 −1 src/Symfony/Component/Form/Extension/Csrf/CsrfProvider/CsrfProviderInterface.php
  18. +13 −2 src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php
  19. +1 −1 src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php
  20. +3 −3 src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php
  21. +1 −1 src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php
  22. +61 −39 src/Symfony/Component/Form/Form.php
  23. +3 −3 src/Symfony/Component/Form/FormConfigBuilderInterface.php
  24. +1 −1 src/Symfony/Component/Form/FormConfigInterface.php
  25. +21 −3 src/Symfony/Component/Form/FormEvents.php
  26. +15 −15 src/Symfony/Component/Form/FormInterface.php
  27. +3 −3 src/Symfony/Component/Form/NativeRequestHandler.php
  28. +1 −1 src/Symfony/Component/Form/README.md
  29. +3 −3 src/Symfony/Component/Form/RequestHandlerInterface.php
  30. +4 −4 src/Symfony/Component/Form/SubmitButton.php
  31. +1 −1 src/Symfony/Component/Form/Tests/AbstractFormTest.php
  32. +2 −2 src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
  33. +18 −18 src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php
  34. +27 −27 src/Symfony/Component/Form/Tests/CompoundFormTest.php
  35. +3 −3 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixRadioInputListenerTest.php
  36. +3 −3 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
  37. +9 −9 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/MergeCollectionListenerTest.php
  38. +22 −22 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/ResizeFormListenerTest.php
  39. +3 −3 src/Symfony/Component/Form/Tests/Extension/Core/EventListener/TrimListenerTest.php
  40. +10 −10 src/Symfony/Component/Form/Tests/Extension/Core/Type/CheckboxTypeTest.php
  41. +30 −30 src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php
  42. +8 −8 src/Symfony/Component/Form/Tests/Extension/Core/Type/CollectionTypeTest.php
  43. +10 −10 src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php
  44. +16 −16 src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
  45. +5 −5 src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php
  46. +29 −29 src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php
  47. +1 −1 src/Symfony/Component/Form/Tests/Extension/Core/Type/IntegerTypeTest.php
  48. +6 −6 src/Symfony/Component/Form/Tests/Extension/Core/Type/PasswordTypeTest.php
  49. +2 −2 src/Symfony/Component/Form/Tests/Extension/Core/Type/RepeatedTypeTest.php
  50. +6 −6 src/Symfony/Component/Form/Tests/Extension/Core/Type/SubmitTypeTest.php
  51. +18 −18 src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php
  52. +4 −4 src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php
  53. +1 −1 src/Symfony/Component/Form/Tests/Extension/Csrf/EventListener/CsrfValidationListenerTest.php
  54. +5 −5 src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php
  55. +8 −8 src/Symfony/Component/Form/Tests/Extension/HttpFoundation/EventListener/BindRequestListenerTest.php
  56. +7 −7 src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php
  57. +2 −2 src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php
  58. +4 −4 src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php
  59. +10 −10 src/Symfony/Component/Form/Tests/Fixtures/FixedFilterListener.php
  60. +5 −5 src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php
  61. +106 −106 src/Symfony/Component/Form/Tests/SimpleFormTest.php
@@ -20,9 +20,25 @@ UPGRADE FROM 2.x to 3.0

### Form

* Passing a `Symfony\Component\HttpFoundation\Request` instance to
`FormInterface::bind()` was disabled. You should use
`FormInterface::handleRequest()` instead.
* The methods `Form::bind()` and `Form::isBound()` were removed. You should
use `Form::submit()` and `Form::isSubmitted()` instead.

Before:

```
$form->bind(array(...));
```

After:

```
$form->submit(array(...));
```

* Passing a `Symfony\Component\HttpFoundation\Request` instance, as was
supported by `FormInterface::bind()`, is not possible with
`FormInterface::submit()` anymore. You should use `FormInterface::handleRequest()`
instead.

Before:

@@ -39,20 +55,20 @@ UPGRADE FROM 2.x to 3.0
After:

```
$form->handleRequest();
$form->handleRequest($request);
if ($form->isValid()) {
// ...
}
```

If you want to test whether the form was submitted separately, you can use
the method `isBound()`:
the method `isSubmitted()`:

```
$form->handleRequest();
$form->handleRequest($request);
if ($form->isBound()) {
if ($form->isSubmitted()) {
// ...
if ($form->isValid()) {
@@ -61,6 +77,25 @@ UPGRADE FROM 2.x to 3.0
}
```

* The events PRE_BIND, BIND and POST_BIND were renamed to PRE_SUBMIT, SUBMIT
and POST_SUBMIT.

Before:

```
$builder->addEventListener(FormEvents::PRE_BIND, function (FormEvent $event) {
// ...
});
```

After:

```
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
// ...
});
```

* The option "virtual" was renamed to "inherit_data".

Before:
@@ -30,7 +30,7 @@ public static function getSubscribedEvents()
{
// Higher priority than core MergeCollectionListener so that this one
// is called before
return array(FormEvents::BIND => array('onBind', 10));
return array(FormEvents::SUBMIT => array('onBind', 10));
}
public function onBind(FormEvent $event)
@@ -196,7 +196,7 @@ public function testConfigureQueryBuilderWithClosureReturningNonQueryBuilder()
},
));
$field->bind('2');
$field->submit('2');
}
public function testSetDataSingleNull()
@@ -248,7 +248,7 @@ public function testSubmitSingleExpandedNull()
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
));
$field->bind(null);
$field->submit(null);
$this->assertNull($field->getData());
$this->assertSame(array(), $field->getViewData());
@@ -262,7 +262,7 @@ public function testSubmitSingleNonExpandedNull()
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
));
$field->bind(null);
$field->submit(null);
$this->assertNull($field->getData());
$this->assertSame('', $field->getViewData());
@@ -275,7 +275,7 @@ public function testSubmitMultipleNull()
'em' => 'default',
'class' => self::SINGLE_IDENT_CLASS,
));
$field->bind(null);
$field->submit(null);
$this->assertEquals(new ArrayCollection(), $field->getData());
$this->assertSame(array(), $field->getViewData());
@@ -296,7 +296,7 @@ public function testSubmitSingleNonExpandedSingleIdentifier()
'property' => 'name',
));
$field->bind('2');
$field->submit('2');
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData());
@@ -319,7 +319,7 @@ public function testSubmitSingleNonExpandedCompositeIdentifier()
));
// the collection key is used here
$field->bind('1');
$field->submit('1');
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData());
@@ -342,7 +342,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifier()
'property' => 'name',
));
$field->bind(array('1', '3'));
$field->submit(array('1', '3'));
$expected = new ArrayCollection(array($entity1, $entity3));
@@ -370,7 +370,7 @@ public function testSubmitMultipleNonExpandedSingleIdentifierForExistingData()
$existing = new ArrayCollection(array(0 => $entity2));
$field->setData($existing);
$field->bind(array('1', '3'));
$field->submit(array('1', '3'));
// entry with index 0 ($entity2) was replaced
$expected = new ArrayCollection(array(0 => $entity1, 1 => $entity3));
@@ -399,7 +399,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifier()
));
// because of the composite key collection keys are used
$field->bind(array('0', '2'));
$field->submit(array('0', '2'));
$expected = new ArrayCollection(array($entity1, $entity3));
@@ -427,7 +427,7 @@ public function testSubmitMultipleNonExpandedCompositeIdentifierExistingData()
$existing = new ArrayCollection(array(0 => $entity2));
$field->setData($existing);
$field->bind(array('0', '2'));
$field->submit(array('0', '2'));
// entry with index 0 ($entity2) was replaced
$expected = new ArrayCollection(array(0 => $entity1, 1 => $entity3));
@@ -454,7 +454,7 @@ public function testSubmitSingleExpanded()
'property' => 'name',
));
$field->bind('2');
$field->submit('2');
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData());
@@ -480,7 +480,7 @@ public function testSubmitMultipleExpanded()
'property' => 'name',
));
$field->bind(array('1', '3'));
$field->submit(array('1', '3'));
$expected = new ArrayCollection(array($entity1, $entity3));
@@ -510,7 +510,7 @@ public function testOverrideChoices()
'property' => 'name',
));
$field->bind('2');
$field->submit('2');
$this->assertEquals(array(1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')), $field->createView()->vars['choices']);
$this->assertTrue($field->isSynchronized());
@@ -535,7 +535,7 @@ public function testGroupByChoices()
'group_by' => 'groupName',
));
$field->bind('2');
$field->submit('2');
$this->assertSame('2', $field->getViewData());
$this->assertEquals(array(
@@ -599,7 +599,7 @@ public function testDisallowChoicesThatAreNotIncludedChoicesSingleIdentifier()
'property' => 'name',
));
$field->bind('3');
$field->submit('3');
$this->assertFalse($field->isSynchronized());
$this->assertNull($field->getData());
@@ -620,7 +620,7 @@ public function testDisallowChoicesThatAreNotIncludedChoicesCompositeIdentifier(
'property' => 'name',
));
$field->bind('2');
$field->submit('2');
$this->assertFalse($field->isSynchronized());
$this->assertNull($field->getData());
@@ -644,7 +644,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderSingleIdentifie
'property' => 'name',
));
$field->bind('3');
$field->submit('3');
$this->assertFalse($field->isSynchronized());
$this->assertNull($field->getData());
@@ -668,7 +668,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureSingle
'property' => 'name',
));
$field->bind('3');
$field->submit('3');
$this->assertFalse($field->isSynchronized());
$this->assertNull($field->getData());
@@ -692,7 +692,7 @@ public function testDisallowChoicesThatAreNotIncludedQueryBuilderAsClosureCompos
'property' => 'name',
));
$field->bind('2');
$field->submit('2');
$this->assertFalse($field->isSynchronized());
$this->assertNull($field->getData());
@@ -712,7 +712,7 @@ public function testSubmitSingleStringIdentifier()
'property' => 'name',
));
$field->bind('foo');
$field->submit('foo');
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity1, $field->getData());
@@ -734,7 +734,7 @@ public function testSubmitCompositeStringIdentifier()
));
// the collection key is used here
$field->bind('0');
$field->submit('0');
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity1, $field->getData());
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\AlreadyBoundException;
use Symfony\Component\Form\Exception\AlreadySubmittedException;
use Symfony\Component\Form\Exception\BadMethodCallException;
/**
@@ -34,7 +34,7 @@ class Button implements \IteratorAggregate, FormInterface
/**
* @var Boolean
*/
private $bound = false;
private $submitted = false;
/**
* Creates a new button from a form configuration.
@@ -258,9 +258,9 @@ public function getConfig()
*
* @return Boolean true if the button was submitted.
*/
public function isBound()
public function isSubmitted()
{
return $this->bound;
return $this->submitted;
}
/**
@@ -356,21 +356,21 @@ public function handleRequest($request = null)
}
/**
* Binds data to the button.
* Submits data to the button.
*
* @param null|string $submittedData The data
*
* @return Button The button instance
*
* @throws Exception\AlreadyBoundException If the form has already been bound.
* @throws Exception\AlreadySubmittedException If the button has already been submitted.
*/
public function bind($submittedData)
public function submit($submittedData)
{
if ($this->bound) {
throw new AlreadyBoundException('A form can only be bound once');
if ($this->submitted) {
throw new AlreadySubmittedException('A form can only be submitted once');
}
$this->bound = true;
$this->submitted = true;
return $this;
}
@@ -18,6 +18,12 @@ CHANGELOG
* added component-level exceptions for various SPL exceptions
changed all uses of the deprecated Exception class to use more specialized exceptions instead
removed NotInitializedException, NotValidException, TypeDefinitionException, TypeLoaderException, CreationException
* added events PRE_SUBMIT, SUBMIT and POST_SUBMIT
* deprecated events PRE_BIND, BIND and POST_BIND
* [BC BREAK] renamed bind() and isBound() in FormInterface to submit() and isSubmitted()
* added methods submit() and isSubmitted() to Form
* deprecated bind() and isBound() in Form
* deprecated AlreadyBoundException in favor of AlreadySubmittedException

2.2.0
-----
@@ -24,9 +24,9 @@ interface DataTransformerInterface
* This method is called on two occasions inside a form field:
*
* 1. When the form field is initialized with the data attached from the datasource (object or array).
* 2. When data from a request is bound using {@link Form::bind()} to transform the new input data
* back into the renderable format. For example if you have a date field and bind '2009-10-10' onto
* it you might accept this value because its easily parsed, but the transformer still writes back
* 2. When data from a request is submitted using {@link Form::submit()} to transform the new input data
* back into the renderable format. For example if you have a date field and submit '2009-10-10'
* you might accept this value because its easily parsed, but the transformer still writes back
* "2009/10/10" onto the form field (for further displaying or other purposes).
*
* This method must be able to deal with empty values. Usually this will
@@ -52,7 +52,7 @@ public function transform($value);
* Transforms a value from the transformed representation to its original
* representation.
*
* This method is called when {@link Form::bind()} is called to transform the requests tainted data
* This method is called when {@link Form::submit()} is called to transform the requests tainted data
* into an acceptable format for your data processing/model layer.
*
* This method must be able to deal with empty values. Usually this will
@@ -11,6 +11,12 @@
namespace Symfony\Component\Form\Exception;
/**
* Alias of {@link AlreadySubmittedException}.
*
* @deprecated Deprecated since version 2.3, to be removed in 3.0. Use
* {@link AlreadySubmittedException} instead.
*/
class AlreadyBoundException extends LogicException
{
}
Oops, something went wrong.

0 comments on commit 41b0127

Please sign in to comment.
You can’t perform that action at this time.