-
Notifications
You must be signed in to change notification settings - Fork 66
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
Added image type #37
Added image type #37
Conversation
@@ -0,0 +1,61 @@ | |||
<?php | |||
|
|||
namespace Doctrine\Bundle\PHPCRBundle\Document; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we put the Image Document into phpcr-odm itself? (this is really a question, i am not sure if it makes much sense)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't know either :)
Can we leave it here for now and move it when its needed somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving would be a BC break so not ideal. any opinions, @lsmith77 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets put it into the ODM since we already have a couple of documents there. i guess we can then also default to this inside CreateBundle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do. Yes, the one in CreateBundle looks pretty much the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added PR to ODM: doctrine/phpcr-odm#250
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you. Now this PR is not considered WIP anymore. Or is there something left that should be adapted?
@@ -0,0 +1,4 @@ | |||
{% block phpcr_image_widget %} | |||
{{ form_widget(form) }} | |||
<img src="{{ form.vars.data | imagine_filter('image_upload_thumbnail') }}" alt="" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens with this widget if i have not yet uploaded an image?
and what is the standard way with the symfony Form to distinguish between "user did not upload a new file" and "user wants to remove that file"?
is this imagine filter using the copy of the image, so in the end file system to display it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh yeah, if I have not yet uploaded an image, I still try to display it - will fix.
I don't know how we can distinguish between "no new file uploaded" and "file should be removed" - does someone know? Maybe add a checkbox to explicitly delete it?
Yes, imagine_filter uses a file system copy. Will try to add a listener to make sure we clear the imagine cache whenever a new image gets set
how exactly does it work with showing the image? is the imagine filter fine for all? or do we need an image controller? should we port https://github.com/symfony-cmf/CreateBundle/blob/master/Controller/PHPCRImageController.php here? or should all go through imagine? |
|
||
class ModelToFileTransformer implements DataTransformerInterface | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for blank line here I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Wow, really nice. It would be usefull to also provide an option to delete the image. This can be used when an image is not required: the user uploaded one and then does not want the image anymore. Here is a gist from a project, could save some time if you want to add it: https://gist.github.com/rmsint/ad4d8804e3ae6fae2160 |
ah cool. so you just add another field to the form to explicitly delete. sounds reasonable. when/where do you actually delete the image in your gist? can we access that in the data transformer? the event listener sounds not straightforward for me. ah, or do we need it and can't make it in the custom type directly because we don't know at that point if we will have data or not? |
@dbu the type cannot handle data. It is about configuring the Form object, so it occurs before using the Form object. As you need to access the data to determine whether the field should be added, it can only be done later. |
Nice @rmsint thx for that gist, will try to add this. However there are two things that are unclear to me:
|
|
Is this type only for "updloaded" documents? What about documents that already exist, e.g. a user avatar? Should this be renamed to "phpcr_odm_image_upload" so that we can free up "phpcr_odm_image" to display, change and remove existing images? |
@dantleech well the type is to handle images in forms. which usually means uploading the image. i think the only other thing that could be would be providing the image by url and have the server grab it from there, but that is rather the special case. the Image document could be used for other contexts than the image form type we discuss here. but when would you need a phpcr_odm_image form type whithout uploading? @rmsint thanks for the clarifications. so i guess we have to do the same in our Image document, not remove the file on null but have a removeFile method that can be triggered by the checkbox. @elHornair do you think you can manage that? guess we need to update the document in phpcr-odm as well. |
Well, you might want to change the image reference to another existing image, for example another in a media library. In that case the media library would handle the upload.Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté. David Buchmann notifications@github.com a écrit : @dantleech well the type is to handle images in forms. which usually means uploading the image. i think the only other thing that could be would be providing the image by url and have the server grab it from there, but that is rather the special case. the Image document could be used for other contexts than the image form type we discuss here. but when would you need a phpcr_odm_image form type whithout uploading? @rmsint thanks for the clarifications. so i guess we have to do the same in our Image document, not remove the file on null but have a removeFile method that can be triggered by the checkbox. @elHornair do you think you can manage that? guess we need to update the document in phpcr-odm as well. — |
ok, i see. but that would then be a sonata_media_image or something, or not? |
for the documentation, this would belong into this section: http://symfony.com/doc/master/cmf/bundles/phpcr-odm.html#form-types |
Hmm... the more I think about this the less sure I am that it should belong here, after all, there is nothing |
imagine should probably be added to composer.json? |
@dantleech thanks for voicing concerns, better now than being sorry later. i think for the full scale media management, there is SonataMediaBundle which people are working on integrating with the cmf. this is just a small piece and it does bring the @Burgov yes, alain is going to add a suggest entry for imagine. if people do not want to use the form type, they do not need imagine, so its not creating a new hard dependency. we could even add an option to configure if you want preview - without preview there is no imagine needed at all. @rmsint i will extract your gist and suggestion into a new ticket, atm we will just delete the whole document to get rid of the image (that really depends on the use case what makes sense, so your suggestion has value and should be implemented, but we can't do everything right now, as much as i would wish so...) |
Did the cleanup. Thanks a lot for your explanations @rmsint |
i created #40 to keep the information from rmsint regarding the delete file checkbox. its a cool idea and if somebody has time would be a nice addition. |
doc started here symfony-cmf/symfony-cmf-docs#97 |
@dbu I didn't realise the PHPCR-ODM had an Image class, so this PR makes sense to me now :) |
This PR adds an phpcr odm image type that can be used in forms to upload an image that is stored in a PHPCR repository.