minor #20204 3.0 Upgrade Guide: Describing how to pass data to a form 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
This commit is contained in:
commit
adf20c86fb
@ -348,6 +348,58 @@ UPGRADE FROM 2.x to 3.0
|
|||||||
$form = $this->createForm(MyType::class);
|
$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 alias option of the `form.type_extension` tag was removed in favor of
|
||||||
the `extended_type`/`extended-type` option.
|
the `extended_type`/`extended-type` option.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user