Commit d9e5ceea authored by jaapjansma's avatar jaapjansma
Browse files

Fixed public download links

parent 9678d619
......@@ -30,6 +30,11 @@ class DocumentDownloadLink extends AbstractSimpleFieldOutputHandler {
*/
protected $returnUrl = false;
/**
* @var bool
*/
protected $public = false;
/**
* Returns the label of the field for selecting a field.
*
......@@ -63,12 +68,12 @@ class DocumentDownloadLink extends AbstractSimpleFieldOutputHandler {
$repo = \CRM_Documents_Entity_DocumentRepository::singleton();
$document = $repo->getDocumentById($documentId);
$url = $document->getCurrentVersion()->getAttachment()->url;
if ($this->public) {
if ($this->public && $url) {
// Generate a frontend link.
$fileEntityId = $document->getCurrentVersion()->getId();
$fileId = $document->getCurrentVersion()->getAttachment()->fileID;
$fileHash = CRM_Core_BAO_File::generateFileHash($fileEntityId, $fileId);
$url = CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$fileEntityId}&fcs={$fileHash}", TRUE, NULL, TRUE, TRUE);
$fileHash = \CRM_Core_BAO_File::generateFileHash($fileEntityId, $fileId);
$url = \CRM_Utils_System::url('civicrm/file', "reset=1&id={$fileId}&eid={$fileEntityId}&fcs={$fileHash}", TRUE, NULL, TRUE, TRUE);
}
if ($this->returnUrl) {
......@@ -96,6 +101,7 @@ class DocumentDownloadLink extends AbstractSimpleFieldOutputHandler {
public function initialize($alias, $title, $configuration) {
parent::initialize($alias, $title, $configuration);
$this->returnUrl = isset($configuration['return_url']) ? $configuration['return_url'] : false;
$this->public = isset($configuration['public']) ? $configuration['public'] : false;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment