mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
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:
parent
a617be30fe
commit
e925aa1979
@ -62,14 +62,30 @@ class SubmittedFileField extends SubmittedFormField
|
|||||||
*/
|
*/
|
||||||
public function getLink()
|
public function getLink()
|
||||||
{
|
{
|
||||||
$file = $this->UploadedFile();
|
if ($file = $this->getUploadedFileFromDraft()) {
|
||||||
if ($file && $file->exists()) {
|
if ($file->exists()) {
|
||||||
if (trim($file->getFilename(), '/') != trim(ASSETS_DIR, '/')) {
|
return $file->getAbsoluteURL();
|
||||||
return $this->UploadedFile()->AbsoluteLink();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Return the name of the file, if present
|
||||||
*
|
*
|
||||||
@ -77,8 +93,8 @@ class SubmittedFileField extends SubmittedFormField
|
|||||||
*/
|
*/
|
||||||
public function getFileName()
|
public function getFileName()
|
||||||
{
|
{
|
||||||
if ($this->UploadedFile()) {
|
if ($file = $this->getUploadedFileFromDraft()) {
|
||||||
return $this->UploadedFile()->Name;
|
return $file->Name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user