File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 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
8787shipping type. This is achieved by fixing the ``choices `` to a list of available
8888shipping options.
8989
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+
9096Creating a Template for the Field
9197---------------------------------
9298
Original file line number Diff line number Diff line change @@ -735,6 +735,36 @@ class to the ``div`` element around each row:
735735 </div>
736736 {% endblock form_row %}
737737
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+
738768.. tip ::
739769
740770 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.
3737| Inherited | - `attr `_ |
3838| options | - `auto_initialize `_ |
3939| | - `block_name `_ |
40+ | | - `block_prefix `_ |
4041| | - `disabled `_ |
4142| | - `label `_ |
4243| | - `translation_domain `_ |
@@ -154,6 +155,8 @@ of the form type tree (i.e. it cannot be used as a form type on its own).
154155
155156.. include :: /reference/forms/types/options/block_name.rst.inc
156157
158+ .. include :: /reference/forms/types/options/block_prefix.rst.inc
159+
157160.. include :: /reference/forms/types/options/disabled.rst.inc
158161
159162.. 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