Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to link a document to a .pdf file + filter on extension #99

Open
nicolas-bastien opened this issue Apr 14, 2014 · 11 comments
Open

How to link a document to a .pdf file + filter on extension #99

nicolas-bastien opened this issue Apr 14, 2014 · 11 comments
Labels
Milestone

Comments

@nicolas-bastien
Copy link
Member

Hi,

I spent time reading the doc and looking at the sandbox and right now I found how to link my document to an image with a 'cmf_media_image' form type but nothing for simple file.

When I try to use a file form type i have this error :
*
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class PHPCRProxies__CG__\Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File to an instance of Symfony\Component\HttpFoundation\File\File.
*

I need this to have a downloadable pdf file and a video.

I don't understand why there is no 'cmf_media_file' form type ?

And is there a way to limit to a list of file extension ?

Thanks a lot

Nico

@dbu
Copy link
Member

dbu commented Apr 15, 2014

indeed i think we miss a cmf media FileType that would look very similar (and probably can share code with) ImageType. do you want to have a look at what we do for the image and try to generalize that to handle plain files?

we already have the FileController with downloadAction - i guess that should have a viewAction that omits the Content-Disposition so the file can be viewed in a browser directly (again without duplicating all the code there)

for the file extensions, that would be a general symfony question. i found nothing here http://symfony.com/doc/current/reference/forms/types/file.html
this is a whole can of worms, as you have both the mime type and the extension to worry about, and in general can not trust the client to respect things. but i propose you discuss that in the core symfony channels as its not related specifically to the cmf.

@rmsint do you have inputs for nicolas?

@nicolas-bastien
Copy link
Member Author

Ok David thanks for your answer.

So just to be sure, the first line of the mediabundle doc say :

Media can be images, binary documents (like pdf files), embedded movies, uploaded movies, MP3s, etc.

So you confirm than right now only images works ?

Did somebody already try to use SonataMedia with the CMF ?

Thanks a lot

@rmsint
Copy link
Contributor

rmsint commented Apr 16, 2014

Hey Nicolas,

Underneath some inputs from my side, hope it helps you further. (It is some time ago I worked with Symfony, so my knowledge may be a bit rusty.)

Form Type
For a file upload you can use the symfony file form type. After that persist it to phpcr using the Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperDoctrine:handleUploadedFile. See the webtest/demo app for an example: https://github.com/symfony-cmf/MediaBundle/blob/master/Tests/Resources/Controller/PhpcrFileTestController.php#L58

Of course you can make it easier, fe. to use with sonata admin, by creating a form type cmf_media_file that puts the last step in a transformer. Actually, the transformer Symfony\Cmf\Bundle\MediaBundle\Form\DataTransformer\ModelToFileTransformer is already handling files and images, so it is just a matter of creating the form type. You can also control then how an uploaded file is rendered, fe. you maybe want to display the filename and filesize and/or a thumnail for your pdf. If it is that generic, and more people can benefit, you could do a PR?

Here a the steps and links how this is done for the cmf_media_image:

See also https://github.com/symfony-cmf/symfony-cmf/wiki/Media, it describes some ideas we had before writing this bundle. If I remember correctly there has been some discussion about a PDF having a preview image, there should be a note about this.

File extensions
If the file extensions are important to your application you can add some guards to your model. Fe. a PDF file that only accepts the pdf extension. You could use the symfony validation and/or add guards directly in the model for the content setters. Whatever suits your app best I would say. Symfony has already some code to map between mime-types and extensions, see https://github.com/symfony/HttpFoundation/blob/master/File/UploadedFile.php#L173.

@dbu
Copy link
Member

dbu commented Apr 16, 2014

thanks a lot for the inputs roel.

regarding mime-types, see also #77

@rmsint
Copy link
Contributor

rmsint commented Apr 16, 2014

@nicolas-bastien, for me: yes and no. No with the CmfMediaBundle. Yes, before this bundle existed I had an integration working with SonataMedia and the CMF. I think now 70% of the work is done for integrating with SonataMedia. The Gaufrette adapter is created to do the heavy lifting of the integration with SonataMediaBundle. I expect most work needs to be done in the SonataMediaBundle, and maybe some bugfixes in the CmfMediaBundle.

@nicolas-bastien
Copy link
Member Author

Hi, thanks so much for your answers.

I will do that next week. I need to make it work on my project before the
end of april.
Then I'll help improving the bundle.

Thanks again for your help

Nico

On 16 April 2014 16:12, Roel Sint [email protected] wrote:

@nicolas-bastien https://github.com/nicolas-bastien, for me: yes and
no. No with the CmfMediaBundle. Yes, before this bundle existed I had an
integration working with SonataMedia and the CMF. I think now 70% of the
work is done for integrating with SonataMedia. The Gaufrette adapter is
created to do the heavy lifting of the integration with SonataMediaBundle.
I expect most work needs to be done in the SonataMediaBundle, and maybe
some bugfixes in the CmfMediaBundle.


Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-40603208
.

@rmsint
Copy link
Contributor

rmsint commented Apr 23, 2014

@nicolas-bastien see sonata-project/SonataMediaBundle#509. Another discussion to pickup integration with SonataMediaBundle

@dbu
Copy link
Member

dbu commented May 8, 2014

do we need to do anything on the cmf side?

@nicolas-bastien
Copy link
Member Author

Hi,

So thanks to your help I managed to make a file input field.
One problem is that every time I update my document the file (like the
image) field is deleted.

To correct that I made a custom admin and use a sonata_type_admin.

So my media solution is not really great, I'll come back when something
will be working.

Nico

On 8 May 2014 17:45, David Buchmann [email protected] wrote:

do we need to do anything on the cmf side?


Reply to this email directly or view it on GitHubhttps://github.com//issues/99#issuecomment-42566259
.

@dbu
Copy link
Member

dbu commented May 13, 2014

you did see that our models check if the file is being set to null and in that case do not remove the child?

@dbu
Copy link
Member

dbu commented Oct 21, 2014

ping @nicolas-bastien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants