Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b69bd3f

Browse filesBrowse files
smithandrefabpot
authored andcommitted
3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver
1 parent d24c340 commit b69bd3f
Copy full SHA for b69bd3f

File tree

Expand file treeCollapse file tree

1 file changed

+52
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+52
-0
lines changed

‎UPGRADE-3.0.md

Copy file name to clipboardExpand all lines: UPGRADE-3.0.md
+52Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.