-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
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.
controller/upload_file.rst
Outdated
@@ -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) { |
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.
it should be :
elseif ($file instanceof File) {
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.
Thank you @Simperfit updated!
controller/upload_file.rst
Outdated
} 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()); |
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.
Typo: setBrocure
-> setBrochure
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.
@javiereguiluz thank you for the feedback :)
cough 😊 |
@matt9mg sorry for not having reviewed this sooner. Let's ping @vudaltsov because he recently reviewed another change proposal related to file upload. Thanks! |
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.
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()); |
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.
Yes this prevents a cast to string.
Thank you @matt9mg. |
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
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.