From 48f0d4fe0810f7307e41e29f025cfb688a960e07 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 27 Jul 2022 11:13:11 +0200 Subject: [PATCH] Expanding recommendation for `finishView()`... ... to include the widgets created by ChoiceType as well. Might conflict with a minor change I just did in https://github.com/symfony/symfony-docs/pull/17066 --- form/create_custom_field_type.rst | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index 75e07fddfb6..dbca331e050 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -133,17 +133,30 @@ These are the most important methods that a form type class can define: ``buildView()`` It sets any extra variables you'll need when rendering the field in a template. -``finishView()`` - When creating a form type that consists of many fields, this method allows - to modify the "view" of any of those fields. For any other use case, it's - recommended to use ``buildView()`` instead. - ``configureOptions()`` It defines the options configurable when using the form type, which are also the options that can be used in ``buildForm()`` and ``buildView()`` methods. Options are inherited from parent types and parent type extensions, but you can create any custom option you need. +``finishView()`` + This method allows to modify the "view" of any rendered widget. This is useful + if your form type consists of many fields, or contains a type that produces + many HTML elements (e.g. ``ChoiceType``). For any other use case, it's + recommended to use ``buildView()`` instead. + +``getParent()`` + If your custom type is based on another type (i.e. they share some + functionality) add this method to return the fully-qualified class name + of that original type. Do not use PHP inheritance for this. + Symfony will call all the form type methods (``buildForm()``, + ``buildView()``, etc.) of the parent type and it will call all its type + extensions before calling the ones defined in your custom type. + + By default, the ``AbstractType`` class returns the generic + :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\FormType` + type, which is the root parent for all form types in the Form component. + Defining the Form Type ~~~~~~~~~~~~~~~~~~~~~~