Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adf20c8

Browse files
committed
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
2 parents d24c340 + b69bd3f commit adf20c8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

UPGRADE-3.0.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,58 @@ UPGRADE FROM 2.x to 3.0
348348
$form = $this->createForm(MyType::class);
349349
```
350350

351+
* Passing custom data to forms now needs to be done
352+
through the options resolver.
353+
354+
In the controller:
355+
356+
Before:
357+
```php
358+
$form = $this->createForm(new MyType($variable), $entity, array(
359+
'action' => $this->generateUrl('action_route'),
360+
'method' => 'PUT',
361+
));
362+
```
363+
After:
364+
```php
365+
$form = $this->createForm(MyType::class, $entity, array(
366+
'action' => $this->generateUrl('action_route'),
367+
'method' => 'PUT',
368+
'custom_value' => $variable,
369+
));
370+
```
371+
In the form type:
372+
373+
Before:
374+
```php
375+
class MyType extends AbstractType
376+
{
377+
private $value;
378+
379+
public function __construct($variableValue)
380+
{
381+
$this->value = $value;
382+
}
383+
// ...
384+
}
385+
```
386+
387+
After:
388+
```php
389+
public function buildForm(FormBuilderInterface $builder, array $options)
390+
{
391+
$value = $options['custom_value'];
392+
// ...
393+
}
394+
395+
public function configureOptions(OptionsResolver $resolver)
396+
{
397+
$resolver->setDefaults(array(
398+
'custom_value' => null,
399+
));
400+
}
401+
```
402+
351403
* The alias option of the `form.type_extension` tag was removed in favor of
352404
the `extended_type`/`extended-type` option.
353405

0 commit comments

Comments
 (0)