File tree 4 files changed +53
-0
lines changed
4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -87,6 +87,12 @@ The goal of this field was to extend the choice type to enable selection of the
87
87
shipping type. This is achieved by fixing the ``choices `` to a list of available
88
88
shipping options.
89
89
90
+ .. tip ::
91
+
92
+ If the purpose of this new form type was to customize the rendering of some
93
+ fields only, skip this step and use ``block_name `` or ``block_prefix `` option
94
+ instead. For more information, see :ref: `form-customization-form-themes `.
95
+
90
96
.. tip ::
91
97
92
98
Run the following command to verify that the form type was successfully
Original file line number Diff line number Diff line change @@ -735,6 +735,36 @@ class to the ``div`` element around each row:
735
735
</div>
736
736
{% endblock form_row %}
737
737
738
+ .. tip ::
739
+
740
+ If you want to customize some instances of the same form only (without
741
+ the need to create a new form type) you can set the ``block_prefix ``
742
+ option in your form type::
743
+
744
+ use Symfony\Component\Form\Extension\Core\Type\TextType;
745
+ use Symfony\Component\Form\FormBuilderInterface;
746
+
747
+ public function buildForm(FormBuilderInterface $builder, array $options)
748
+ {
749
+ $builder->add('name', TextType::class, array(
750
+ 'block_prefix' => 'wrapped_text',
751
+ ));
752
+ }
753
+
754
+ .. versionadded :: 4.3
755
+
756
+ The ``block_prefix `` option was introduced in Symfony 4.3.
757
+
758
+ Then the block name will be ``wrapped_text_row ``.
759
+
760
+ .. code-block :: html+twig
761
+
762
+ {% block wrapped_text_row %}
763
+ <div class="wrapped">
764
+ {{ form_row(form) }}
765
+ </div>
766
+ {% endblock wrapped_text_row %}
767
+
738
768
.. tip ::
739
769
740
770
See :ref: `form-theming-methods ` for how to apply this customization.
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ on all types for which ``FormType`` is the parent.
37
37
| Inherited | - `attr `_ |
38
38
| options | - `auto_initialize `_ |
39
39
| | - `block_name `_ |
40
+ | | - `block_prefix `_ |
40
41
| | - `disabled `_ |
41
42
| | - `label `_ |
42
43
| | - `translation_domain `_ |
@@ -156,6 +157,8 @@ of the form type tree (i.e. it cannot be used as a form type on its own).
156
157
157
158
.. include :: /reference/forms/types/options/block_name.rst.inc
158
159
160
+ .. include :: /reference/forms/types/options/block_prefix.rst.inc
161
+
159
162
.. include :: /reference/forms/types/options/disabled.rst.inc
160
163
161
164
.. include :: /reference/forms/types/options/label.rst.inc
Original file line number Diff line number Diff line change
1
+ block_prefix
2
+ ~~~~~~~~~~~~
3
+
4
+ **type**: ``string`` or ``null`` **default **: ``null`` (see :ref:`Knowing which
5
+ block to customize <form-customization-sidebar>`)
6
+
7
+ .. versionadded:: 4.3
8
+
9
+ The ``block_prefix`` option was introduced in Symfony 4.3 .
10
+
11
+ Allows you to add a custom block prefix and override the block name
12
+ used to render the form type. Useful for example if you have multiple
13
+ instances of the same form and you need to personalize the rendering
14
+ of all of them without the need to create a new form type.
You can’t perform that action at this time.
0 commit comments