Skip to content

Commit 15e3bcd

Browse files
committed
Add list of public files to tinymce link action
1 parent d995883 commit 15e3bcd

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

classes/components/forms/FieldRichTextarea.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class FieldRichTextarea extends Field
3535
/** @var string Optional. The API endpoint to upload images to. Only include if image uploads are supported here. */
3636
public $uploadUrl;
3737

38+
/** @var string Optional. Array of available links to public files. */
39+
public $linkList;
40+
3841
/** @var int Optional. When a word limit is specified a word counter will be shown */
3942
public $wordLimit = 0;
4043

@@ -55,6 +58,11 @@ public function getConfig()
5558
if (!empty($this->uploadUrl)) {
5659
$config['uploadUrl'] = $this->uploadUrl;
5760
}
61+
62+
if (!empty($this->linkList)) {
63+
$config['linkList'] = $this->linkList;
64+
}
65+
5866
if ($this->wordLimit) {
5967
$config['wordLimit'] = $this->wordLimit;
6068
$config['wordCountLabel'] = __('publication.wordCount');

classes/components/forms/context/PKPMastheadForm.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace PKP\components\forms\context;
1717

18+
use APP\core\Application;
19+
use PKP\db\DAORegistry;
1820
use PKP\components\forms\FieldRichTextarea;
1921
use PKP\components\forms\FieldSelect;
2022
use PKP\components\forms\FieldText;
@@ -51,6 +53,23 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
5153
return strcmp($a['label'], $b['label']);
5254
});
5355

56+
// Add list of links to public
57+
$request = Application::get()->getRequest();
58+
$context = $request->getContext();
59+
$libraryFileDao = DAORegistry::getDAO('LibraryFileDAO');
60+
$contextId = $context->getId();
61+
$files = $libraryFileDao->getByContextId($contextId);
62+
$linkList = [];
63+
64+
while ($file = $files->next()) {
65+
if ($file->getPublicAccess()){
66+
$linkList[] = [
67+
"title" => $file->getLocalizedName(),
68+
"value" => $request->getDispatcher()->url(Application::get()->getRequest(), Application::ROUTE_PAGE, null, 'libraryFiles', 'downloadPublic', [$file->getId()])
69+
];
70+
}
71+
}
72+
5473
$this->addGroup([
5574
'id' => 'identity',
5675
'label' => __('manager.setup.identity'),
@@ -96,6 +115,7 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
96115
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
97116
'plugins' => ['link','lists','image','code'],
98117
'uploadUrl' => $imageUploadUrl,
118+
'linkList' => $linkList,
99119
'value' => $context->getData('editorialHistory'),
100120
]))
101121
->addGroup([
@@ -107,17 +127,19 @@ public function __construct($action, $locales, $context, $imageUploadUrl)
107127
'description' => __('manager.setup.contextSummary.description'),
108128
'isMultilingual' => true,
109129
'groupId' => 'about',
130+
'linkList' => $linkList,
110131
'value' => $context->getData('description'),
111132
]))
112133
->addField(new FieldRichTextarea('about', [
113134
'label' => __('manager.setup.contextAbout'),
114135
'description' => __('manager.setup.contextAbout.description'),
115136
'isMultilingual' => true,
116137
'size' => 'large',
117-
'groupId' => 'about',
138+
'groupId' => 'about',
118139
'toolbar' => 'bold italic superscript subscript | link | blockquote bullist numlist | image | code',
119140
'plugins' => ['link','lists','image','code'],
120141
'uploadUrl' => $imageUploadUrl,
142+
'linkList' => $linkList,
121143
'value' => $context->getData('about'),
122144
]));
123145
}

controllers/grid/files/LibraryFileGridCellProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getTemplateVarsFromRowColumn($row, $column)
4545
// handled by our link action.
4646
return ['label' => ''];
4747
case 'url':
48-
return ['label' => $request->getDispatcher()->url(Application::get()->getRequest(), Application::ROUTE_PAGE, null, 'libraryFiles', 'downloadPublic', [$element->getId()])];
48+
return $element->getPublicAccess() ? ['label' => $request->getDispatcher()->url(Application::get()->getRequest(), Application::ROUTE_PAGE, null, 'libraryFiles', 'downloadPublic', [$element->getId()])] : ['label' => ''];
4949
}
5050
}
5151

0 commit comments

Comments
 (0)