Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc6ba1a

Browse filesBrowse files
committed
minor #9079 preUpdate Event Listener On Uploaded Imagery (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
2 parents 4c8b0b4 + a4cc43a commit dc6ba1a
Copy full SHA for dc6ba1a

File tree

1 file changed

+5
-0
lines changed
Filter options

1 file changed

+5
-0
lines changed

‎controller/upload_file.rst

Copy file name to clipboardExpand all lines: controller/upload_file.rst
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ automatically upload the file when persisting the entity::
310310
namespace AppBundle\EventListener;
311311

312312
use Symfony\Component\HttpFoundation\File\UploadedFile;
313+
use Symfony\Component\HttpFoundation\File\File;
313314
use Doctrine\ORM\Event\LifecycleEventArgs;
314315
use Doctrine\ORM\Event\PreUpdateEventArgs;
315316
use AppBundle\Entity\Product;
@@ -351,6 +352,10 @@ automatically upload the file when persisting the entity::
351352
if ($file instanceof UploadedFile) {
352353
$fileName = $this->uploader->upload($file);
353354
$entity->setBrochure($fileName);
355+
} elseif ($file instanceof File) {
356+
// prevents the full file path being saved on updates
357+
// as the path is set on the postLoad listener
358+
$entity->setBrochure($file->getFilename());
354359
}
355360
}
356361
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.