Repository navigation
Expand file tree
/
Copy pathLiveKeywordSplitterPlugin.inc.php
More file actions
71 lines (60 loc) · 1.86 KB
/
Copy pathLiveKeywordSplitterPlugin.inc.php
File metadata and controls
71 lines (60 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @file plugins/generic/liveKeywordSplitter/LiveKeywordSplitterPlugin.inc.php
*
* Copyright (c) 2026 Thuan Huynh
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
*/
namespace APP\plugins\generic\liveKeywordSplitter;
use APP\core\Application;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class LiveKeywordSplitterPlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register
*/
public function register($category, $path, $mainContextId = null): bool
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
Hook::add('TemplateManager::display', $this->registerJavaScript(...));
}
return $success;
}
/**
* Get the display name of this plugin.
* @return String
*/
public function getDisplayName()
{
return __('plugins.generic.liveKeywordSplitter.displayName');
}
/**
* Get a description of the plugin.
*/
public function getDescription()
{
return __('plugins.generic.liveKeywordSplitter.description');
}
/**
* Load the splitter on every backend page. Keyword fields in OJS 3.5 can
* be rendered after the initial page load (for example, in the Editor
* Dashboard metadata side modal), so filtering by the initial template is
* not reliable.
*/
public function registerJavaScript(string $hookName, array $args): bool
{
$templateMgr = $args[0];
$request = Application::get()->getRequest();
$templateMgr->addJavaScript(
'liveKeywordSplitter',
rtrim($request->getBaseUrl(), '/') . '/' . $this->getPluginPath() . '/js/live-splitter-min.js?v=1.1.0.1',
[
'contexts' => ['backend'],
]
);
return false;
}
}