8000 minor #7981 Update upload_file.rst (rumours86) · symfony/symfony-docs@7fb0887 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7fb0887

Browse files
committed
minor #7981 Update upload_file.rst (rumours86)
This PR was submitted for the 3.3 branch but it was merged into the 2.7 branch instead (closes #7981). Discussion ---------- Update upload_file.rst If you edit an existing product with an attached file and do not fill in the fields for the file, after saving the field with the file is reset Commits ------- d015048 Update upload_file.rst
2 parents 581bebb + d015048 commit 7fb0887

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

controller/upload_file.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ automatically upload the file when persisting the entity::
332332
class BrochureUploadListener
333333
{
334334
private $uploader;
335+
private $fileName;
335336

336337
public function __construct(FileUploader $uploader)
337338
{
@@ -362,11 +363,10 @@ automatically upload the file when persisting the entity::
362363
$file = $entity->getBrochure();
363364

364365
// only upload new files
365-
if (!$file instanceof UploadedFile) {
366-
return;
366+
if ($file instanceof UploadedFile) {
367+
$fileName = $this->uploader->upload($file);
367368
}
368369

369-
$fileName = $this->uploader->upload($file);
370370
$entity->setBrochure($fileName);
371371
}
372372
}
@@ -449,8 +449,9 @@ controller.
449449
return;
450450
}
451451

452-
if ($fileName = $entity->getBrochure()) {
453-
$entity->setBrochure(new File($this->uploader->getTargetDir().'/'.$fileName));
452+
$this->fileName = $entity->getBrochure()
453+
if ($this->fileName) {
454+
$entity->setBrochure(new File($this->uploader->getTargetDir().'/'.$this->fileName));
454455
}
455456
}
456457
}

0 commit comments

Comments
 (0)
0