@@ -7,6 +7,42 @@ Form Types
7
7
The MediaBundle provides a couple of useful form types along with form data
8
8
transformers.
9
9
10
+ A default twig template is also included for these form types.
11
+ To use it you will need to add the ``fields.html.twig `` template from the
12
+ MediaBundle to the ``form.resources `` section in twig config:
13
+
14
+ .. configuration-block ::
15
+
16
+ .. code-block :: yaml
17
+
18
+ twig :
19
+ form :
20
+ resources :
21
+ - ' CmfMediaBundle:Form:fields.html.twig'
22
+
23
+ .. code-block :: xml
24
+
25
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
26
+ <container xmlns =" http://symfony.com/schema/dic/services" >
27
+
28
+ <config xmlns =" http://symfony.com/schem/dic/twig" >
29
+
30
+ <form >
31
+ <resource >CmfMediaBundle:Form:fields.html.twig</resource >
32
+ </form >
33
+ </config >
34
+ </container >
35
+
36
+ .. code-block :: php
37
+
38
+ $container->loadFromExtension('twig', array(
39
+ 'form' => array(
40
+ 'resources' => array(
41
+ 'CmfMediaBundle:Form:fields.html.twig',
42
+ ),
43
+ ),
44
+ ));
45
+
10
46
cmf_media_image
11
47
~~~~~~~~~~~~~~~
12
48
@@ -89,42 +125,6 @@ Then you can add images to document forms as follows::
89
125
it optional when editing an existing document. We are
90
126
`trying to make this automatic `_.
91
127
92
- Next you will need to add the ``fields.html.twig `` template from the
93
- MediaBundle to the ``form.resources ``, to actually see the preview of the
94
- uploaded image in the backend:
95
-
96
- .. configuration-block ::
97
-
98
- .. code-block :: yaml
99
-
100
- twig :
101
- form :
102
- resources :
103
- - ' CmfMediaBundle:Form:fields.html.twig'
104
-
105
- .. code-block :: xml
106
-
107
- <?xml version =" 1.0" encoding =" UTF-8" ?>
108
- <container xmlns =" http://symfony.com/schema/dic/services" >
109
-
110
- <config xmlns =" http://symfony.com/schem/dic/twig" >
111
-
112
- <form >
113
- <resource >CmfMediaBundle:Form:fields.html.twig</resource >
114
- </form >
115
- </config >
116
- </container >
117
-
118
- .. code-block :: php
119
-
120
- $container->loadFromExtension('twig', array(
121
- 'form' => array(
122
- 'resources' => array(
123
- 'CmfMediaBundle:Form:fields.html.twig',
124
- ),
125
- ),
126
- ));
127
-
128
128
The document that should contain the ``Image `` document has to implement a
129
129
setter method. To profit from the automatic guesser of the form layer, the
130
130
name in the form element and this method name have to match. See
@@ -142,6 +142,17 @@ To delete an image, you need to delete the document containing the image.
142
142
changing images with commands, you should handle cache invalidation in the
143
143
command or manually remove the imagine cache afterwards.
144
144
145
+ cmf_media_file
146
+ ~~~~~~~~~~~~~~~
147
+
148
+ .. versionadded: 1.3
149
+ The ``cmf_media_file`` form type was introduced in MediaBundle 1.3.
150
+
151
+ The ``cmf_media_file `` form maps to an object that implements the
152
+ ``Symfony\Cmf\Bundle\MediaBundle\FileInterface ``.
153
+ It renders as a file upload button with a link for downloading the existing
154
+ file, if any.
155
+
145
156
.. _`LiipImagineBundle` : https://github.com/liip/LiipImagineBundle
146
157
.. _`trying to make this automatic` : https://groups.google.com/forum/?fromgroups=#!topic/symfony2/CrooBoaAlO4
147
158
.. _`ImagineBlock::setImage` : https://github.com/symfony-cmf/BlockBundle/blob/master/Doctrine/Phpcr/ImagineBlock.php#L121
0 commit comments