@@ -12,6 +12,13 @@ But sometimes, you don't really need to add new field types - you want
12
12
to add features on top of existing types. This is where form type
13
13
extensions come in.
14
14
15
+ Form type extensions have 2 main use-cases:
16
+
17
+ #. You want to add a **specific feature to a single type ** (such
18
+ as adding a "download" feature to the "file" field type);
19
+ #. You want to add a **generic feature to several types ** (such as
20
+ adding a "help" text to every "text" or "choice"-like type).
21
+
15
22
It might be possible to achieve your goal with custom form rendering, or custom
16
23
form field types. But using form type extensions can be cleaner (by limiting the
17
24
amount of business logic in templates) and more flexible (you can add several
@@ -315,11 +322,14 @@ with an image, you will see it displayed next to the file input.
315
322
Generic Form Type Extensions
316
323
----------------------------
317
324
318
- Although it is not possible to have a form type extension applying to all form
319
- types, **most ** form types natively available in Symfony
320
- (:doc: `/reference/forms/types `) inherit from the ``form `` form type. Thus, a
321
- form type extension applying to ``form `` would apply to all of these.
322
-
323
- A notable exception are the ``button `` from types. Plus, keep in mind that a custom
324
- form type which doesn't inherit neither ``form `` nor ``button `` could always be
325
- created.
325
+ You can modify several form types at once by specifying their common parent
326
+ (:doc: `/reference/forms/types `). For example, several form types natively
327
+ available in Symfony inherit from the ``text `` form type (such as ``email ``,
328
+ ``search ``, ``url ``, etc.). A form type extension applying to ``text `` would
329
+ apply to all of these form types.
330
+
331
+ In the same way, since **most ** form types natively available in Symfony inherit
332
+ from the ``form `` form type, a form type extension applying to ``form `` would
333
+ apply to all of these. A notable exception are the ``button `` form types. Plus,
334
+ keep in mind that a custom form type which inherit neither ``form `` nor
335
+ ``button `` could always be created.
0 commit comments