Skip to content

Commit

Permalink
minor #20204 3.0 Upgrade Guide: Describing how to pass data to a form…
Browse files Browse the repository at this point in the history
… through options resolver (smithandre)

This PR was submitted for the master branch but it was merged into the 2.8 branch instead (closes #20204).

Discussion
----------

3.0 Upgrade Guide: Describing how to pass data to a form through options resolver

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18662
| License       | MIT
| Doc PR        |

Enhanced the upgrade guide by adding details regarding passing data to a form through the options resolver.

Commits
-------

b69bd3f 3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver
  • Loading branch information
fabpot committed Oct 14, 2016
2 parents d24c340 + b69bd3f commit adf20c8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions UPGRADE-3.0.md
Expand Up @@ -348,6 +348,58 @@ UPGRADE FROM 2.x to 3.0
$form = $this->createForm(MyType::class);
```

* Passing custom data to forms now needs to be done
through the options resolver.

In the controller:

Before:
```php
$form = $this->createForm(new MyType($variable), $entity, array(
'action' => $this->generateUrl('action_route'),
'method' => 'PUT',
));
```
After:
```php
$form = $this->createForm(MyType::class, $entity, array(
'action' => $this->generateUrl('action_route'),
'method' => 'PUT',
'custom_value' => $variable,
));
```
In the form type:

Before:
```php
class MyType extends AbstractType
{
private $value;

public function __construct($variableValue)
{
$this->value = $value;
}
// ...
}
```

After:
```php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$value = $options['custom_value'];
// ...
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'custom_value' => null,
));
}
```

* The alias option of the `form.type_extension` tag was removed in favor of
the `extended_type`/`extended-type` option.

Expand Down

1 comment on commit adf20c8

@TomasVotruba
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated 👍

Please sign in to comment.