diff --git a/code/Model/Submission/SubmittedFileField.php b/code/Model/Submission/SubmittedFileField.php
index 94829d934..1a57cce28 100755
--- a/code/Model/Submission/SubmittedFileField.php
+++ b/code/Model/Submission/SubmittedFileField.php
@@ -3,6 +3,7 @@
namespace SilverStripe\UserForms\Model\Submission;
use SilverStripe\Assets\File;
+use SilverStripe\Control\Director;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Versioned\Versioned;
@@ -83,7 +84,11 @@ public function getLink($grant = true)
{
if ($file = $this->getUploadedFileFromDraft()) {
if ($file->exists()) {
- return $file->getURL($grant);
+ $url = $file->getURL($grant);
+ if ($url) {
+ return Director::absoluteURL($url);
+ }
+ return null;
}
}
}
diff --git a/tests/php/Model/SubmittedFileFieldTest.php b/tests/php/Model/SubmittedFileFieldTest.php
index 9db30dc2d..ac6778982 100644
--- a/tests/php/Model/SubmittedFileFieldTest.php
+++ b/tests/php/Model/SubmittedFileFieldTest.php
@@ -5,6 +5,7 @@
use SilverStripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\AssetStore;
+use SilverStripe\Control\Director;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
@@ -69,21 +70,23 @@ public function testDeletingSubmissionRemovesFile()
public function testGetFormattedValue()
{
+ // Set an explicit base URL so we get a reliable value for the test
+ Director::config()->set('alternate_base_url', 'http://mysite.com');
$fileName = $this->submittedFile->getFileName();
$message = "You don't have the right permissions to download this file";
$this->file->CanViewType = 'OnlyTheseUsers';
$this->file->write();
-
+
$this->loginWithPermission('ADMIN');
$this->assertEquals(
sprintf(
- '%s - Download File',
+ '%s - Download File',
$fileName
),
$this->submittedFile->getFormattedValue()->value
);
-
+
$this->loginWithPermission('CMS_ACCESS_CMSMain');
$this->assertEquals(
sprintf(