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

File upload - Form type for 'content' property instead of entire document #136

Closed
eiannone opened this issue Jul 20, 2015 · 5 comments
Closed

Comments

@eiannone
Copy link
Contributor

I noticed that MediaBundle defines only a form type for image documents (called 'cmf_media_image'), and doesn't have any basic type for generic binary files (like for example a 'cmf_media_file', or a 'cmf_media_binary'). This was discussed also in #99.

Regarding the definition of this new form type for generic file documents, I was wondering if it would make sense to link it to the 'content' property of the ODM Document, rather than to the entire document itself. I.e. instead of using '...MediaBundle\Doctrine\Phpcr\File' as data_class, use 'Doctrine\ODM\PHPCR\Document\Resource'.
This because a document class extending Phpcr\File could have other properties mapped to different form fields, such as author, description and dates, some of which can be required, and other no, and we want to control them individually, while the file upload part should only be relevant to the binary data.
What do you think about?

@dbu
Copy link
Member

dbu commented Jul 21, 2015 via email

@eiannone
Copy link
Contributor Author

OK, so I'll try to implement this ResourceFormType, calling it 'cmf_media_resource', as a child of 'file' form type.
We need also a ModelToResourceTransformer, similar to ModelToFileTransformer, and a FileUploadHandler, similar to UploadFileHelperDoctrine.
But as in this case we are dealing only with the uploaded binary data, simply converting it to a Resource object, we don't need neither Doctrine and MediaManager dependency nor EditorHelper stuff (I suppose), so maybe I could put the upload/transformation logic in the data transformer, without the need of a separate FileUploadHandler.
I'm new to MediaBundle, so I am not sure if this is correct. I will test it to see if it works.

@dbu
Copy link
Member

dbu commented Jul 22, 2015 via email

@eiannone
Copy link
Contributor Author

I think I was wrong about mapping File document properties to a form.
After looking at the code more carefully, I realized that all those properties of the File object should be considered as file metadata and not supposed to be editable in a web form.
From what I understand, their values may be extracted from file binary data, for example by the UploadFileHelper during upload, by the MediaManager after upload, or by an EventSubscriber (see DoctrineImageDimensionsSubscriber for example) which hooks prePersist event for the file document and set properties just before it is persisted.
If we need additional editable fields/properties related to the file, we should create a separate "content" document, of which the file document will become a child, like it was done in the MediaBundle WebTest examples for the image document.

So I reverted back to the idea of creating a cmf_media_file form type linked to the entire File document and submitted a PR: #137
So as far as I'm concerned this issue can be closed.

@dbu
Copy link
Member

dbu commented Jul 24, 2015

see #137

@dbu dbu closed this as completed Jul 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants