FIX Uploaded files not appearing in emails

As files uploaded into `DRAFT` mode ensure that these are still displayed in the submitted form.
This commit is contained in:
Will Rossiter 2021-03-22 21:30:14 +13:00 committed by GitHub
parent a617be30fe
commit e925aa1979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,14 +62,30 @@ class SubmittedFileField extends SubmittedFormField
*/
public function getLink()
{
$file = $this->UploadedFile();
if ($file && $file->exists()) {
if (trim($file->getFilename(), '/') != trim(ASSETS_DIR, '/')) {
return $this->UploadedFile()->AbsoluteLink();
if ($file = $this->getUploadedFileFromDraft()) {
if ($file->exists()) {
return $file->getAbsoluteURL();
}
}
}
/**
* As uploaded files are stored in draft by default, this retrieves the
* uploaded file from draft mode rather than using the current stage.
*
* @return File
*/
public function getUploadedFileFromDraft(): ?File
{
$fileId = $this->UploadedFileID;
return Versioned::withVersionedMode(function() use ($fileId) {
Versioned::set_stage(Versioned::DRAFT);
return File::get()->byID($fileId);
});
}
/**
* Return the name of the file, if present
*
@ -77,8 +93,8 @@ class SubmittedFileField extends SubmittedFormField
*/
public function getFileName()
{
if ($this->UploadedFile()) {
return $this->UploadedFile()->Name;
if ($file = $this->getUploadedFileFromDraft()) {
return $file->Name;
}
}
}