Skip to content

Commit edf6e32

Browse files
matt9mgGuikingone
authored andcommitted
preUpdate Event Listener On Uploaded Imagery
1 parent 9e485a8 commit edf6e32

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

controller/upload_file.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ automatically upload the file when persisting the entity::
335335
namespace App\EventListener;
336336

337337
use Symfony\Component\HttpFoundation\File\UploadedFile;
338+
use Symfony\Component\HttpFoundation\File\File;
338339
use Doctrine\ORM\Event\LifecycleEventArgs;
339340
use Doctrine\ORM\Event\PreUpdateEventArgs;
340341
use App\Entity\Product;
@@ -376,6 +377,10 @@ automatically upload the file when persisting the entity::
376377
if ($file instanceof UploadedFile) {
377378
$fileName = $this->uploader->upload($file);
378379
$entity->setBrochure($fileName);
380+
} elseif ($file instanceof File) {
381+
// prevents the full file path being saved on updates
382+
// as the path is set on the postLoad listener
383+
$entity->setBrochure($file->getFilename());
379384
}
380385
}
381386
}

0 commit comments

Comments
 (0)