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

Skip to content

Commit 7f8a40e

Browse files
committed
update customization guide form
1 parent 8781f2f commit 7f8a40e

1 file changed

Lines changed: 22 additions & 15 deletions

File tree

docs/customization/form.rst

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ You can:
1919
How to customize a Form?
2020
~~~~~~~~~~~~~~~~~~~~~~~~
2121

22+
.. tip::
23+
24+
You can browse the full implementation of this example on GitHub
25+
on the `<https://github.com/Sylius/Customizations/pull/8>`_
26+
2227
If you want to modify the form for the ``Customer Profile`` in your system there are a few steps that you should take.
2328
Assuming that you would like to (for example):
2429

@@ -58,9 +63,6 @@ As a result you will get the ``Sylius\Bundle\CustomerBundle\Form\Type\CustomerPr
5863
5964
final class CustomerProfileTypeExtension extends AbstractTypeExtension
6065
{
61-
/**
62-
* {@inheritdoc}
63-
*/
6466
public function buildForm(FormBuilderInterface $builder, array $options): void
6567
{
6668
// Adding new fields works just like in the parent form type.
@@ -78,12 +80,9 @@ As a result you will get the ``Sylius\Bundle\CustomerBundle\Form\Type\CustomerPr
7880
]);
7981
}
8082
81-
/**
82-
* {@inheritdoc}
83-
*/
84-
public function getExtendedType(): string
83+
public static function getExtendedTypes(): iterable
8584
{
86-
return CustomerProfileType::class;
85+
return [CustomerProfileType::class];
8786
}
8887
}
8988
@@ -105,8 +104,8 @@ As a result you will get the ``Sylius\Bundle\CustomerBundle\Form\Type\CustomerPr
105104
Of course remember that you need to render the new fields you have created,
106105
and remove the rendering of the fields that you have removed **in your views**.
107106

108-
In our case you will need to copy the original template from `vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Account/profileUpdate.html.twig`
109-
to `templates/bundles/SyliusShopBundle/Account/` and add the fields inside the copy
107+
In our case you will need to copy the original template from ``vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Resources/views/Account/profileUpdate.html.twig``
108+
to ``templates/bundles/SyliusShopBundle/Account/`` and add the fields inside the copy
110109

111110
.. code-block:: html
112111

@@ -139,6 +138,14 @@ For instance the ``ProductVariant`` admin form is defined under ``Sylius/Bundle/
139138
140139
your form extension will also be executed. Whether before or after the other extensions depends on priority tag set.
141140

141+
How to customize a Form when form elements are embedded dynamically?
142+
--------------------------------------------------------------------
143+
144+
.. tip::
145+
146+
You can browse the full implementation of this example on GitHub
147+
on the `<https://github.com/Sylius/Customizations/pull/9>`_
148+
142149
Having a look at the extensions and possible additionally defined event handlers can also be useful when form elements are embedded dynamically,
143150
as is done in the ``ProductVariantTypeExtension`` by the ``CoreBundle``:
144151

@@ -150,9 +157,6 @@ as is done in the ``ProductVariantTypeExtension`` by the ``CoreBundle``:
150157
151158
final class ProductVariantTypeExtension extends AbstractTypeExtension
152159
{
153-
/**
154-
* {@inheritdoc}
155-
*/
156160
public function buildForm(FormBuilderInterface $builder, array $options): void
157161
{
158162
...
@@ -173,7 +177,6 @@ as is done in the ``ProductVariantTypeExtension`` by the ``CoreBundle``:
173177
]);
174178
});
175179
}
176-
177180
...
178181
}
179182
@@ -202,7 +205,6 @@ you will also have to set up an event listener and then remove the field:
202205
;
203206
204207
...
205-
206208
}
207209
}
208210
@@ -217,6 +219,11 @@ Although it is advised to follow the :doc:`Validation Customization Guide </cust
217219
want to define the form constraints from inside the form extension. They will not be used unless the correct validation group(s)
218220
has been added. The example below shows how to add the default `sylius` group to a constraint.
219221

222+
.. tip::
223+
224+
You can browse the full implementation of this example on GitHub
225+
on the `<https://github.com/Sylius/Customizations/pull/8>`_
226+
220227
.. code-block:: php
221228
222229
<?php

0 commit comments

Comments
 (0)