File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Original file line number Diff line number Diff line change @@ -348,6 +348,58 @@ UPGRADE FROM 2.x to 3.0
348
348
$form = $this->createForm(MyType::class);
349
349
```
350
350
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
+
351
403
* The alias option of the `form.type_extension` tag was removed in favor of
352
404
the `extended_type`/`extended-type` option.
353
405
You can’t perform that action at this time.
0 commit comments