Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0f44de

Browse files
committed
minor #10835 [Form] Documenting the block_prefix option (yceruto)
This PR was squashed before being merged into the master branch (closes #10835). Discussion ---------- [Form] Documenting the block_prefix option Documenting new feature: symfony/symfony#29680 Commits ------- d9382d4 [Form] Documenting the block_prefix option
2 parents 6bcb0a1 + d9382d4 commit e0f44de

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

form/create_custom_field_type.rst

Lines 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
.. tip::
9197

9298
Run the following command to verify that the form type was successfully

form/form_customization.rst

Lines 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

Lines 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`_ |
@@ -156,6 +157,8 @@ of the form type tree (i.e. it cannot be used as a form type on its own).
156157

157158
.. include:: /reference/forms/types/options/block_name.rst.inc
158159

160+
.. include:: /reference/forms/types/options/block_prefix.rst.inc
161+
159162
.. include:: /reference/forms/types/options/disabled.rst.inc
160163

161164
.. include:: /reference/forms/types/options/label.rst.inc
Lines 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)