Skip to content

preUpdate Event Listener On Uploaded Imagery #9079

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

Closed
wants to merge 3 commits into from

Conversation

matt9mg
Copy link
Contributor

@matt9mg matt9mg commented Jan 19, 2018

I've noticed a scenario (a bit of an edge case when uploading imagery).

If you have an entity (say a brochure) but you can give it a title and an image and the image title can be updated without the image being updated (the file type is not an UploadedFile but a File on save it'll persist the full file path instead of the desired filename. The above is a safety measure to ensure the above.

I've noticed a scenario (a bit of an edge case when uploading imagery).

If you have an entity (say a brochure) but you can give it a title and an image and the image title can be updated without the image being updated (the file type is not an UploadedFile but a File on save it'll persist the full file path instead of the desired filename. The above is a safety measure to ensure the above.
@matt9mg matt9mg changed the title Post Load Event Listener preUpdate Event Listener Jan 19, 2018
@matt9mg matt9mg changed the title preUpdate Event Listener preUpdate Event Listener On Uploaded Imagery Jan 19, 2018
@@ -362,6 +363,10 @@ automatically upload the file when persisting the entity::
if ($file instanceof UploadedFile) {
$fileName = $this->uploader->upload($file);
$entity->setBrochure($fileName);
} elseif($file instanceof File) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be :
elseif ($file instanceof File) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Simperfit updated!

} elseif ($file instanceof File) {
// prevents the full file path being saved on updates
// as the path is set on the postLoad listener
$entity->setBrocure($file->getFilename());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: setBrocure -> setBrochure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiereguiluz thank you for the feedback :)

@xabbuh xabbuh added this to the 2.7 milestone Jan 22, 2018
@matt9mg
Copy link
Contributor Author

matt9mg commented Apr 27, 2018

cough 😊

@javiereguiluz javiereguiluz modified the milestones: 2.7, 2.8 May 28, 2018
@javiereguiluz
Copy link
Member

@matt9mg sorry for not having reviewed this sooner. Let's ping @vudaltsov because he recently reviewed another change proposal related to file upload. Thanks!

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

} elseif ($file instanceof File) {
// prevents the full file path being saved on updates
// as the path is set on the postLoad listener
$entity->setBrochure($file->getFilename());
Copy link
Contributor

@HeahDude HeahDude Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this prevents a cast to string.

@xabbuh
Copy link
Member

xabbuh commented Aug 7, 2018

Thank you @matt9mg.

xabbuh added a commit that referenced this pull request Aug 7, 2018
This PR was submitted for the 4.0 branch but it was squashed and merged into the 2.8 branch instead (closes #9079).

Discussion
----------

preUpdate Event Listener On Uploaded Imagery

I've noticed a scenario (a bit of an edge case when uploading imagery).

If you have an entity (say a brochure) but you can give it a title and an image and the image title can be updated without the image being updated (the file type is not an UploadedFile but a File on save it'll persist the full file path instead of the desired filename. The above is a safety measure to ensure the above.

Commits
-------

a4cc43a preUpdate Event Listener On Uploaded Imagery
@xabbuh xabbuh closed this Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants