From b69bd3f0ed94d9c8138d1cd379e734a67e7ce1bd Mon Sep 17 00:00:00 2001 From: Andre Smith Date: Tue, 11 Oct 2016 17:48:30 +0200 Subject: [PATCH] 3.0 Upgrade Guide: Added details describing how to pass data to a form through the options resolver --- UPGRADE-3.0.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index b8b4a96223..68e3780d8a 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -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.