Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Form] Documenting the block_prefix option#10835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionsform/create_custom_field_type.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -87,6 +87,12 @@ The goal of this field was to extend the choice type to enable selection of the
shipping type. This is achieved by fixing the ``choices`` to a list of available
shipping options.

.. tip::

If the purpose of this new form type was to customize the rendering of some
fields only, skip this step and use ``block_name`` or ``block_prefix`` option
instead. For more information, see :ref:`form-customization-form-themes`.

Creating a Template for the Field
---------------------------------

Expand Down
30 changes: 30 additions & 0 deletionsform/form_customization.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -735,6 +735,36 @@ class to the ``div`` element around each row:
</div>
{% endblock form_row %}

.. tip::

If you want to customize some instances of the same form only (without
the need to create a new form type) you can set the ``block_prefix``
option in your form type::

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class, array(
'block_prefix' => 'wrapped_text',
));
}

.. versionadded:: 4.3

The ``block_prefix`` option was introduced in Symfony 4.3.

Then the block name will be ``wrapped_text_row``.

.. code-block:: html+twig

{% block wrapped_text_row %}
<div class="wrapped">
{{ form_row(form) }}
</div>
{% endblock wrapped_text_row %}

.. tip::

See :ref:`form-theming-methods` for how to apply this customization.
Expand Down
3 changes: 3 additions & 0 deletionsreference/forms/types/form.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@ on all types for which ``FormType`` is the parent.
| Inherited | - `attr`_ |
| options | - `auto_initialize`_ |
| | - `block_name`_ |
| | - `block_prefix`_ |
| | - `disabled`_ |
| | - `label`_ |
| | - `translation_domain`_ |
Expand DownExpand Up@@ -154,6 +155,8 @@ of the form type tree (i.e. it cannot be used as a form type on its own).

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

.. include:: /reference/forms/types/options/block_prefix.rst.inc

.. include:: /reference/forms/types/options/disabled.rst.inc

.. include:: /reference/forms/types/options/label.rst.inc
Expand Down
14 changes: 14 additions & 0 deletionsreference/forms/types/options/block_prefix.rst.inc
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
block_prefix
~~~~~~~~~~~~

**type**: ``string`` or ``null`` **default**: ``null`` (see :ref:`Knowing which
block to customize <form-customization-sidebar>`)

.. versionadded:: 4.3

The ``block_prefix`` option was introduced in Symfony 4.3.

Allows you to add a custom block prefix and override the block name
used to render the form type. Useful for example if you have multiple
instances of the same form and you need to personalize the rendering
of all of them without the need to create a new form type.

[8]ページ先頭

©2009-2025 Movatter.jp