symfony/symfony — pull request #5576 by ericclemmons (2012-09-23 04:55:38+00:00)
Title: [Form] Add Partial Bind Support

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #1341
Todo: [list of todos pending]
License of the code: MIT
Documentation PR: Not yet

__This is a work in progress__

After much discussion in #1341, I've added the ability for `FormType` to support binding partial data.

### Expectations

My intent is to accomplish the following (via a `partial` option much like `read_only` or `required`):

* `partial` defaults to `false`, so we expect bound data to match the form children.
* Binding a non-partial form behaves as usual (of course!).
* Missing submitted child data simply bypasses calling `bind` on the child.
* Validation on the partial form skips the `isValid` check on unbound children, since they would have never been bound.
* Supplied data for a partial form still binds to children, so validation logic still applies.
* Extra data is still marked as extra data, no matter the type of form.

### Problems

The obvious problem with this approach is that `BindRequestListener` cannot make any changes to `FormConfigBuilder` once the user calls `bindRequest` with a `PATCH` request.

For forms to support a partial `bind`, the user would have to do:

__(Recommended) Solution 1__

```php
$form = $factory->create('firstName', null, array(
'partial' => 'PATCH' === $request,
));
```
The only other method I know of is to modify the `bind` function signature:

__Solution 2__

```php
$form->bind(array(), Form::BIND_PARTIAL);

public function bind($submittedData, $method = Form::BIND_ALL)
```

__Solution 3__

We can introduce another event for modifying `FormConfigBuilder` _before_ `setDataLocked` is called. However, this would make forms much more volatile & introduce "magic", in my opinion, where the state of the form is never concrete until _after_ binding is complete.