Skip to content

Commit a4cc43a

Browse files
matt9mgxabbuh
authored andcommitted
preUpdate Event Listener On Uploaded Imagery
1 parent 4c8b0b4 commit a4cc43a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

controller/upload_file.rst

+5
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)