From 417885e5cf2d1077643d38beb8352cfcc0c9e91c Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 3 Jan 2019 08:22:34 -0500 Subject: [PATCH 1/2] Documenting the block_prefix option --- form/create_custom_field_type.rst | 6 ++++ form/form_customization.rst | 29 +++++++++++++++++++ reference/forms/types/form.rst | 3 ++ .../forms/types/options/block_prefix.rst.inc | 13 +++++++++ 4 files changed, 51 insertions(+) create mode 100644 reference/forms/types/options/block_prefix.rst.inc diff --git a/form/create_custom_field_type.rst b/form/create_custom_field_type.rst index 63f07ef8974..76ed91c9593 100644 --- a/form/create_custom_field_type.rst +++ b/form/create_custom_field_type.rst @@ -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 --------------------------------- diff --git a/form/form_customization.rst b/form/form_customization.rst index f5ab9ef2dc5..8c3da42b9c8 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -735,6 +735,35 @@ class to the ``div`` element around each row: {% 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 %} +
+ {{ form_row(form) }} +
+ {% endblock wrapped_text_row %} + .. tip:: See :ref:`form-theming-methods` for how to apply this customization. diff --git a/reference/forms/types/form.rst b/reference/forms/types/form.rst index d3b58111bff..ff5d91811fe 100644 --- a/reference/forms/types/form.rst +++ b/reference/forms/types/form.rst @@ -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`_ | @@ -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 diff --git a/reference/forms/types/options/block_prefix.rst.inc b/reference/forms/types/options/block_prefix.rst.inc new file mode 100644 index 00000000000..085508600ee --- /dev/null +++ b/reference/forms/types/options/block_prefix.rst.inc @@ -0,0 +1,13 @@ +block_prefix +~~~~~~~~~~~~ + +**type**: ``string`` or ``null`` **default**: ``null`` (see :ref:`Knowing which +block to customize `) + +.. 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. From b3e1fc49cf13ae9c2eee27291748e459301e5daa Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 3 Jan 2019 18:26:05 -0500 Subject: [PATCH 2/2] Add blank line after versionadded directive --- form/form_customization.rst | 1 + reference/forms/types/options/block_prefix.rst.inc | 1 + 2 files changed, 2 insertions(+) diff --git a/form/form_customization.rst b/form/form_customization.rst index 8c3da42b9c8..f6205819526 100644 --- a/form/form_customization.rst +++ b/form/form_customization.rst @@ -752,6 +752,7 @@ class to the ``div`` element around each row: } .. versionadded:: 4.3 + The ``block_prefix`` option was introduced in Symfony 4.3. Then the block name will be ``wrapped_text_row``. diff --git a/reference/forms/types/options/block_prefix.rst.inc b/reference/forms/types/options/block_prefix.rst.inc index 085508600ee..f02feb0ce70 100644 --- a/reference/forms/types/options/block_prefix.rst.inc +++ b/reference/forms/types/options/block_prefix.rst.inc @@ -5,6 +5,7 @@ block_prefix block to customize `) .. 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy