Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 29265c3

Browse files
committed
Merge pull request #689 from eiannone/patch-2
Documented new 'cmf_media_file' form type
2 parents 03be7cb + 46fbfe3 commit 29265c3

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

bundles/media/form_types.rst

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,42 @@ Form Types
77
The MediaBundle provides a couple of useful form types along with form data
88
transformers.
99

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+
1046
cmf_media_image
1147
~~~~~~~~~~~~~~~
1248

@@ -89,42 +125,6 @@ Then you can add images to document forms as follows::
89125
it optional when editing an existing document. We are
90126
`trying to make this automatic`_.
91127

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-
128128
The document that should contain the ``Image`` document has to implement a
129129
setter method. To profit from the automatic guesser of the form layer, the
130130
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.
142142
changing images with commands, you should handle cache invalidation in the
143143
command or manually remove the imagine cache afterwards.
144144

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+
145156
.. _`LiipImagineBundle`: https://github.com/liip/LiipImagineBundle
146157
.. _`trying to make this automatic`: https://groups.google.com/forum/?fromgroups=#!topic/symfony2/CrooBoaAlO4
147158
.. _`ImagineBlock::setImage`: https://github.com/symfony-cmf/BlockBundle/blob/master/Doctrine/Phpcr/ImagineBlock.php#L121

0 commit comments

Comments
 (0)