@@ -296,68 +296,8 @@ form.type_extension
296
296
297
297
**Purpose**: Create a custom " form extension"
298
298
299
- Form type extensions are a way for you took " hook into" the creation of any
300
- field in your form. For example, the addition of the CSRF token is done via
301
- a form type extension (:class:`Symfony\\Component\\Form\\Extension\\Csrf\\Type\\FormTypeCsrfExtension`).
302
-
303
- A form type extension can modify any part of any field in your form. To create
304
- a form type extension, first create a class that implements the
305
- :class:`Symfony\\Component\\Form\\FormTypeExtensionInterface` interface.
306
- For simplicity, you'll often extend an
307
- :class:`Symfony\\Component\\Form\\AbstractTypeExtension` class instead of
308
- the interface directly::
309
-
310
- // src/Acme/MainBundle/Form/Type/MyFormTypeExtension.php
311
- namespace Acme\MainBundle\Form\Type;
312
-
313
- use Symfony\Component\Form\AbstractTypeExtension;
314
-
315
- class MyFormTypeExtension extends AbstractTypeExtension
316
- {
317
- // ... fill in whatever methods you want to override
318
- // like buildForm(), buildView(), finishView(), setDefaultOptions()
319
- }
320
-
321
- In order for Symfony to know about your form extension and use it, give it
322
- the ``form.type_extension`` tag:
323
-
324
- .. configuration-block::
325
-
326
- .. code-block:: yaml
327
-
328
- services:
329
- main.form.type.my_form_type_extension:
330
- class: Acme\MainBundle\Form\Type\MyFormTypeExtension
331
- tags:
332
- - { name: form.type_extension, alias: field }
333
-
334
- .. code-block:: xml
335
-
336
- <?xml version=" 1.0" encoding=" UTF-8" ?>
337
- <container xmlns=" http://symfony.com/schema/dic/services"
338
- xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
339
- xsi:schemaLocation=" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
340
-
341
- <services>
342
- <service
343
- id=" main.form.type.my_form_type_extension"
344
- class=" Acme\MainBundle\Form\Type\MyFormTypeExtension" >
345
-
346
- <tag name=" form.type_extension" alias=" field" />
347
- </service>
348
- </services>
349
- </container>
350
-
351
- .. code-block:: php
352
-
353
- $container
354
- ->register('main.form.type.my_form_type_extension', 'Acme\MainBundle\Form\Type\MyFormTypeExtension')
355
- ->addTag('form.type_extension', array('alias' => 'field'))
356
- ;
357
-
358
- The ``alias`` key of the tag is the type of field that this extension should
359
- be applied to. For example, to apply the extension to any form/field, use the
360
- " form" value.
299
+ For details on creating Form type extensions, read the cookbook article:
300
+ :doc:`/cookbook/form/create_form_type_extension`
361
301
362
302
.. _reference-dic-type_guesser:
363
303
0 commit comments