diff --git a/book/forms.rst b/book/forms.rst index 0fde7985056..a3c9dbe9961 100644 --- a/book/forms.rst +++ b/book/forms.rst @@ -1021,6 +1021,29 @@ to the ``form()`` or the ``form_start()`` helper: a PUT, PATCH or DELETE request. Read the cookbook chapter ":doc:`/cookbook/routing/method_parameters`" for more information. +.. note:: + + Now that the ``createForm()`` method requires the FQCN, you can no longer pass in *dynamic* ``__construct()`` arguments. This is not to be confused with :ref:`form-as-services`. To get + around this, you will need to create the default options in the form class ``configureOptions()`` method:: + + use Symfony\Component\OptionsResolver\OptionsResolver; + use Symfony\Component\Form\Extension\Core\Type\PasswordType; + use Symfony\Component\Form\Extension\Core\Type\TextType; + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder->add('username', TextType::class, array('required' => $options['username_required'])); + $builder->add('password', PasswordType::class, array('required' => $options['password_required'])); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'username_required' => true, + 'password_required' => false, + )); + } + .. index:: single: Forms; Creating form classes