Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d9382d4

Browse filesBrowse files
ycerutojaviereguiluz
authored andcommitted
[Form] Documenting the block_prefix option
1 parent 3f20558 commit d9382d4
Copy full SHA for d9382d4

File tree

4 files changed

+53
-0
lines changed
Filter options

4 files changed

+53
-0
lines changed

‎form/create_custom_field_type.rst

Copy file name to clipboardExpand all lines: form/create_custom_field_type.rst
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ The goal of this field was to extend the choice type to enable selection of the
8787
shipping type. This is achieved by fixing the ``choices`` to a list of available
8888
shipping 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+
9096
Creating a Template for the Field
9197
---------------------------------
9298

‎form/form_customization.rst

Copy file name to clipboardExpand all lines: form/form_customization.rst
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

‎reference/forms/types/form.rst

Copy file name to clipboardExpand all lines: reference/forms/types/form.rst
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.